tags:

views:

43

answers:

4

Hi, I create a temporary file on the server, that someone uploads. While I was testing, It was fine to use the complete home directory path in my machine. But now that I have to deploy it to a server, I tried using a ~, but I get a

java.io.FileNotFoundException: ~/test/csvFile.csv (No such file or directory)

how do I use something analogous to a ~ ie short for the home directory in *nix. I am using the java.io.File package.

Thanks.

+4  A: 
System.getProperty("user.home") ; //will return the path to user home directory.

If i understood it correctly you are looking for how to get user dir path

org.life.java
yes, thats correct.
Kaustubh P
@org.life.java ^_^ unfortunately Thilo's answer was correct, but I will upvote because its useful!
Kaustubh P
@Kaustubh P Ok than you can tick his answer as marked :) :)
org.life.java
+2  A: 

~ is deciphered by Unix shell, not by your program. To get the same effect, get the value of "HOME" environmental variable

DVK
+3  A: 

If you really want a temporary file, you should stop caring about which directory this ends up in (usually) and instead use

File tempFile = File.createTempFile("csvFile", ".csv");
Thilo
yeah, much better. thanks!
Kaustubh P
+1  A: 

The user.home system property points to the current user's home directory.

However, you may want to consider File.createTempFile() instead for temporary files.

Grodriguez