This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I'm having some trouble with portability of one of my applications. When I create, access, and modify my files I use relative path names. I always assumed that the path names were relative to the directory containing the class files. Example: My .jar file is in directory X. In X there is a subdirectory subdir ( \X\subdir ) containing some files, for example file1.txt. In my program I attempt to access my files in subdir using the following: File f = new File("subdir\file1.txt") On some machines (mine, a Mac running Mac OS 9) this seems to work, and on others (my friend's, a Mac running Mac OS X) it gives a file not found error. Is there any way to solve this? Are there any web sites that give explicit explanantions of how the JVM resovles file paths? Any help would be appreciated. Micah
Steve Deadsea
Ranch Hand
Joined: Dec 03, 2001
Posts: 125
posted
0
Relative files are relative to the working directory. The working directory is *not* the directory that contains the class files. The working directory is the directory from which the program was started. You can usually start the program from any directory by specifying the classpath as a command line argument. If your classes are packaged in a jar file or served over the internet you still want to be able to find other resources such as translations, images, configuration files, etc that go with your program. You need to treat these files as "system resources". Programs can accesses resources such as images, propery files, help documents, and web pages that are stored in a jar file along with the program. http://java.sun.com/j2se/1.3/docs/guide/resources/