File.separator is portable, / is not, ugly or not always opt for the
more portable option.
For example, this code;
-------------------------------------------------------------------------------
import java.io.*;
public class FileSeparator
{
public static void main(String[] argv)
{
File temp = new File("temp/hello");
File temp2 = new File("temp\\hello");
File temp3 = new File("temp" + File.separator +
"hello");
temp.mkdirs();
System.out.println("dir " + temp +
" exists? "+ temp.exists());
System.out.println("dir " + temp2 +
" exists? " + temp2.exists());
System.out.println("dir " + temp3 +
" exists? " + temp3.exists());
}
}
-------------------------------------------------------------------------------
In Windows it outputs the following;
D:\**\file-separator>java FileSeparator
dir temp\hello exists? true
dir temp\hello exists? true
dir temp\hello exists? true
In Linux (Ubuntu) it outputs the following;
*...@ubuntu:~/**/file-separator$ java FileSeparator
dir temp/hello exists? true
dir temp\hello exists? false
dir temp/hello exists? true
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.