Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

paths

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to read through a flat txt file that I know will always be in the same root directory as my jar file on every machine. However, I don't know what this root directory will be on each machine so how do I make my code flexible enough to be installed on any machine?
I have this situation :
C:\root\myFlatFile.txt
C:\root\myJava.jar
In myJava.jar I have a class that needs to see myFlatFile.txt but it is contained in a subdirectory package. Do I use a series of backslashes to let the software know I want to go back to a root level?
If I'm not being very clear please ask me to elaborate.
Thanks!
 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way would be to have a Properties file with different attributes for different OSs. Within your code check for the LOCALE and the OS and load the appropriate property from the Properties file.
 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Try using the System.getProperty method.
For example
1. System.getProperty("user.dir") will return the
current directory.
2. System.getProperty("file.separator") will return
the appropriate operating system file separator
Cheers
Originally posted by Paul Keohan:
I want to read through a flat txt file that I know will always be in the same root directory as my jar file on every machine. However, I don't know what this root directory will be on each machine so how do I make my code flexible enough to be installed on any machine?
I have this situation :
C:\root\myFlatFile.txt
C:\root\myJava.jar
In myJava.jar I have a class that needs to see myFlatFile.txt but it is contained in a subdirectory package. Do I use a series of backslashes to let the software know I want to go back to a root level?
If I'm not being very clear please ask me to elaborate.
Thanks!

 
prasad bhn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can list the roots of the OS by using the
static File[] listRoots() method of File Class.
as you might have C: and D: for windows OS!
and after that you can follow up easily using the hints by
Toyin Sogeke..
- prasadbh.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!