Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to go in the back to back directory ?  RSS feed

 
Celina Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a properties file which lies in the folder c:\com
and I have a java class in c:\com\org\dtd
folder which loads the properties file.
If I specify the path of the properties file like (in the java class )-
"..\\..\\dtd.properties", I get the FileNotFound Error.
How do I move to the back to back directory ?
 
Paramagurusamy Balasubramanian
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In java we should use front slash instead of back slash to navigate over the directories.
So in your case you should use "..//..//dtd.properties"
Hope this will work fine.
Best Regards,
Paramaguru.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java you "should" use File.separator in place of / or \ to create paths that are appropriate for the system you're running on. But in practice the File class is generally able to parse both / and \ as equivalent, so it usually doesn't matter. The more likely problem in this case is that the position of the .class file is irrelevant here. What matters is what directory are you executing java.exe from. That's the directory that all relative paths are interpreted with respect to. If your class files are organized by package, you probably aren't running from the same directory the file is in. If you don't know where you're running from, try inserting this line:
<pre>
System.out.println("Running java from " + new ?File(".").getAbsolutePath());
</pre>
After you learn where you are, you will have a better change of determining where you should go.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!