0

I'm sure some platforms will not use this naming convention for "this folder" and "this folder's parent", but does Java abstracts that away and returns the expected result across all platforms?

File f = new File("."); //is this the current folder, always, no matter the file system?
File f = new File("..");//equivalent to above, but for the parent folder

Also, are those path symbols always relative to the folder where the jar file resides, or do they sometimes (in some other system) represent some place else, like, for instance, maybe the current folder could be considered the folder where the JVM executable resides.

FinnTheHuman
  • 1,115
  • 13
  • 29
  • 3
    I wouldn't recommend using those no matter what the platform. The concept of "current directory" isn't very well defined, so navigating based on that is always unreliable. – Kayaman Aug 17 '17 at 15:50
  • 2
    The current directory definitely is *not* guaranteed to be the directory containing the .jar file. If you want to bundle read-only files, put them inside your .jar file. If you want to have writable files, use temporary files or [pick a known location like somewhere under the user’s home directory.](https://stackoverflow.com/questions/35388882/find-place-for-dedicated-application-folder) – VGR Aug 17 '17 at 16:13
  • 1
    Java doesn't provide this. The platform does. The current working directory is *neither* the directory where the .jar file is located *nor* the directory where the java executable resides on any platform I am aware of. – user207421 Aug 17 '17 at 16:17
  • Thank you all very much. I wish Java took a lesson from C# here... Anyway, I liked @VGR suggestion to include the files inside the jar. – FinnTheHuman Aug 17 '17 at 16:48
  • As Jaga came first it is impossible to see how that could ever happen, but I strongly suspect you're mistaken about how C# works as well. – user207421 Aug 17 '17 at 22:16

0 Answers0