Temp folder and platform independence

I just discovered that

System.getProperty("java.io.tmpdir","");

returns on windows with a path separator at the end and on linux without which definitely makes a difference.

So this property affects platform independency of an application written in java.

Or is there something I missed?

[368 byte] By [mwildama] at [2007-11-27 11:04:40]
# 1

output on Windows (e.g.): C:\Temp\

output on Linux (e.g.): /tmp

So when on linux I have to add a path separator and on windows I may not add it.

mwildama at 2007-7-29 13:02:43 > top of Java-index,Java Essentials,New To Java...
# 2

It depends on whether you read "platform independence" as "completely transparent platform independence". There are a few gotchas, such as this, that you should account for

georgemca at 2007-7-29 13:02:43 > top of Java-index,Java Essentials,New To Java...
# 3

:-( - This is a trap one easily could fall into and it would be so easy to remove that problem by taking into consideration when reading this information within the JVM.

Is there somewhere a list out there of "known issues" that affect platform independence like this?

mwildama at 2007-7-29 13:02:43 > top of Java-index,Java Essentials,New To Java...
# 4

import java.io.*;

class Foo {

public static void main(String[] args) throws Exception {

String tempdir = System.getProperty("java.io.tmpdir","");

String filename = "temp.txt";

File f = new File(tempdir, filename);

System.out.println(f.getAbsolutePath());

}

}

My results on Windows:

C:\DOCUME~1\yawmark\LOCALS~1\Temp\temp.txt

On Linux (Fedora Core 7):

/tmp/temp.txt

No added (or omitted) slashes necessary.

~

yawmarka at 2007-7-29 13:02:43 > top of Java-index,Java Essentials,New To Java...
# 5

Aha, it seems that the file constructor can handle both - whether the trailing separator exists or not. Maybe this is the reason why nobody is considering this as a problem.

mwildama at 2007-7-29 13:02:43 > top of Java-index,Java Essentials,New To Java...