Home arrow static arrow Java Programming [Archive] - Filename independence
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Filename independence
This topic has 4 replies on 1 page.

Posts:7
Registered: 6/7/04
Filename independence  
Jun 28, 2004 10:09 AM



 
I am writing an app that makes use of a directory structure that houses various ini files to detect settings dynamically. In one of these ini files lies properties/keys for two filepaths.

The problem is that filenames are platform dependent, and if I want this directory structure to be used remotely (on a network drive), I need a way around this. Is there any way to write a filepath that will be platform independent and that I can load it into a File object? I at first thought of using a file: URI, but it seems you still need the drive letter on Windows for it to work.

Any help would be appreciated.
 

Posts:24,036
Registered: 2/3/03
Re: Filename independence  
Jun 28, 2004 10:15 AM (reply 1 of 4)



 
Ensure the properties files are in your classpath. Then you can simply use:
getClass().getResourceAsStream(somePropFile);
 

Posts:31,095
Registered: 4/30/99
Re: Filename independence  
Jun 28, 2004 10:17 AM (reply 2 of 4)



 
It's hard to know what you need to "get around". I suppose the file isn't going to be in the classpath, so you need to know its name before you can access it. Yes, that name might depend on what O/S you're running on, but you still need to hardcode it somewhere (even if it's in a properties file).
 

Posts:7
Registered: 6/7/04
Re: Filename independence  
Jun 28, 2004 10:26 AM (reply 3 of 4)



 
The ini files are loaded based on the directories the user guides the program to.

Anyway, if I were able to use URL's I could get around this. The only problem is I can't search a URL directory with Java, to my knowledge. Is that correct?
 

Posts:31,095
Registered: 4/30/99
Re: Filename independence  
Jun 28, 2004 11:00 AM (reply 4 of 4)



 
There's no such thing as a "URL directory". But if the user is "guiding the program" then there may not be a problem to get around anyway. For example if the user were selecting from a Swing JFileChooser then it automatically returns a file name that is suitable for your operating system.
 
This topic has 4 replies on 1 page.