1

some background: I recently started using Ubuntu, which I heard to use for programming. I'm also making a game that uses directories such as C:\Program Files\Folder\properties.properties which, as you can see, was designed for windows because i just barely transfered. what i want to do is keep coding for windows, because that is currently my designated audience, but do it on ubuntu.

so here is my question:

  1. can i make the directory path (ie. C:\program files\folder\properties.properties) cross platform. so if the os is Ubuntu, it goes /FolderName/properties.properties or whatever, and if it's windows it goes the way i have shown above, and if mac, it does whatever mac does.
  2. if not, is there a way to direct java to C:\program files\folder\properties.properties without actually changing the path. because right now, C: isnt recognized because that isnt how linux works.

Any help would be great! thanks a ton in advance!

EDIT: based on the first answer by @Ron Dahlgren, please answer this: the directory to my running .jar is C:\Program Files\Folder\Files\bin\main.jar and the path to my .properties is C:\Program Files\Folder\Files\User\properties.properties. so i understand how the / works, but how would i make it go up a folder, and access the properties. how does it access the properties file? thanks!

PulsePanda
  • 1,806
  • 10
  • 33
  • 56

1 Answers1

3

As per the accepted answer here, you can just use forward slashes throughout and the JVM will handle the conversion.

In response to your edit, you can use a relative path to each of these items, or have them deployed to the same location to effectively side step the issue.

Community
  • 1
  • 1
  • 1
    And actually, Windows understands `/`. Even a C/C++ program using the Windows API can use `/` instead of `\\` and it works fine. – Eliah Kagan Mar 28 '13 at 22:18
  • so, lets say that on Ubuntu, its at `/bin/Folder`, and on windows its `C:\program files\folder` would i just use `/Folder/whatever else` in the program? – PulsePanda Mar 28 '13 at 22:19
  • No, any path starting with a leading slash is considered absolute - for the relative path suggestion, it would be `Folder/whatever` –  Mar 28 '13 at 22:21
  • @wbAnon I hope you're not creating a folder for your application directly inside `/bin` [on a Unix-like OS such as Ubuntu.](http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) On a Unix-like system, *no* `bin` folder corresponds directly to `Program Files`. If you *need* your whole application and all its supporting files to reside in a single folder, you should put that folder in `/opt`. But it's better not to do that at all. – Eliah Kagan Mar 28 '13 at 22:22
  • it was just an example XD but no, i'm not – PulsePanda Mar 28 '13 at 22:27