This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get a temporary file name

 
Dave Donohoe
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java App that creates a temp file that will be read in by another part of the app at a later stage. I dont want to specify the path, as when the App runs on a different machine, there is no guarantee that the path will be the same ie I dont want to hard code C:\temp\test.txt in the code as C:\ might not exist on the next machine.
Is there anyway around this?
D
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the System.getProperty() to get the current working directory then add the path to your file to that.
 
James Swan
Ranch Hand
Posts: 403
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also check out the createTempFile methods of java.io.File
I haven't tried it myself but this is an extract from the API:
The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Win32 systems it is typically "c:\\temp".
James.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic