Coder's Guild Mailing List

Re: [java] Is there a cross platform way of loading local files in Java?

Posted by Peter Schuller on 2000-06-04

> I am writing a java application that needs to get
> files from certain directories. I am writing this app
> on a Windows box. However I don't want to have it
> explicity get files by using hard coded file paths. I
> would like this app to run on multiple platforms
> without the need to change any code. How can I get the
> files I need without causing errors when run on other
> systems such as Linux, Solaris, etc....????

The details depends on what kind of files you are talking about of course,
but to access "~/.myApp/someFile" (in Unix language), you could do the
following:

File file = new File(System.getProperty("user.home")
	+ File.separator + ".myApp" + File.separator
	+ "someFile");
	
That is, always use File.separator and use "user.home" or similar variables
to control the location of files.

-- 
/ Peter Schuller, InfiDyne Technologies HB

PGP userID: 0x5584BD98 or 'Peter Schuller <peter.schuller@xxxxxxxx.xxx>'
Key retrival: Send an E-Mail to getpgpkey@xxxxx.xxxxxxxx.xxx
E-Mail: peter.schuller@xxxxxxxx.xxx Web: http://scode.infidyne.com