<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Temporary file got override</title><link>https://answers.axonivy.com/questions/4183/temporary-file-got-override</link><description>&lt;p&gt;Hi Fold,&lt;/p&gt;
&lt;p&gt;I got an issue with &lt;code&gt;ch.ivyteam.ivy.scripting.objects.File&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When our Ivy application receive a file via SOAP with the same name all the time Ex: Information.html&lt;/p&gt;
&lt;p&gt;We create a temporary file &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ch.ivyteam.ivy.scripting.objects.File file = new ch.ivyteam.ivy.scripting.objects.File(path,true)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem happens is when 2 requests come at the same time, the second temporary file overrode the first one.&lt;/p&gt;
&lt;p&gt;Is there any way to avoid it without change file name? or add subfolder (caseId) like IDocumentService in temporary file?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/4183/temporary-file-got-override" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 29 Nov 2019 05:45:00 -0500</lastBuildDate><item><title>Comment by Reguel Wermelinger on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4227</link><description>&lt;p&gt;at that's the issue: as soon as 'getJavaFile()' is called, the ivy File impl is no longer in charge to ensure that necessary parent dir structures are created. So you users have to do it manually - as you did.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 29 Nov 2019 05:45:00 -0500</pubDate><guid>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4227</guid></item><item><title>Comment by docvominh on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4226</link><description>&lt;p&gt;I try to write byte[] to that temp file&lt;/p&gt;
&lt;p&gt;FileOutputStream fos = new FileOutputStream(tempFile.getJavaFile());&lt;/p&gt;
&lt;p&gt;fos.write(fileData);&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">docvominh</dc:creator><pubDate>Thu, 28 Nov 2019 22:58:23 -0500</pubDate><guid>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4226</guid></item><item><title>Comment by Christian Strebel on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4200</link><description>&lt;p&gt;If you use ch.ivyteam.ivy.scripting.objects.File it does not work? What method do you call afterwards to the tempFile?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christian Strebel</dc:creator><pubDate>Mon, 25 Nov 2019 06:55:46 -0500</pubDate><guid>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4200</guid></item><item><title>Comment by docvominh on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4198</link><description>&lt;p&gt;Hi Reguel,
Thank for your idea :)&lt;/p&gt;
&lt;p&gt;Sadly, new File() with relative path didn't create folder, and I got file not found exception.&lt;/p&gt;
&lt;p&gt;I must create a folder manually.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;File folder = new File(GuidUtil.generateID(), true);
folder.mkdir();
File tempFile = new File(folder.getName() + "\\" + filename, true);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But problem solved :D&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">docvominh</dc:creator><pubDate>Mon, 25 Nov 2019 06:15:47 -0500</pubDate><guid>https://answers.axonivy.com/questions/4183/temporary-file-got-override#4198</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/4183/temporary-file-got-override/4188</link><description>&lt;p&gt;The  &lt;code&gt;path&lt;/code&gt; parameter is relative. So you can easily include more dynamic parts such as a folder:&lt;/p&gt;
&lt;p&gt;e.g. &lt;code&gt;new File(ch.ivyteam.util.GuidUtil.generateID()/fileName, true)&lt;/code&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Mon, 25 Nov 2019 02:59:58 -0500</pubDate><guid>https://answers.axonivy.com/questions/4183/temporary-file-got-override/4188</guid></item></channel></rss>