• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Working directory question

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic