• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating file using relative path in Java  RSS feed

 
Rajkumar Gandhi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having a java web application. In this application my java classes reside at PROJECT_NAME/src/packages/CLASSES.
I'm having a directory named TEMP which resides at PROJECT_NAME/TEMP.
I want to create files within this TEMP folder using Java code.

I don't want to give absolute path like C:\XXX\YYY, since this will make me to change the file path name in src code each time if I move the application somewhere else.
So, I want to use relative path like PROJECT_Name/TEMP when creating a file as like following,



But this is not working. This statement throws FileNotFoundException

Please help me to resolve this problem.

Thanks,
Rajkumar.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I want to use relative path like PROJECT_Name/TEMP when creating a file as like following,
But this is not working. This statement throws FileNotFoundException

That's not a relative path, path's starting with '/' are absolute paths. You need to find which directory is the default directory and build the path from that point. If you need to go back up the tree one level use '..'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!