File across Operating System
In this chapter you will learn:
path/name separator
Different operating systems use different path
separator. Windows uses \
, while Unix uses /
.
File
class defines file name separator and path
separator which we can use to build string value file path location.
static String pathSeparator
stores system-dependent path-separator character.static char pathSeparatorChar
stores system-dependent path-separator character.static String separator
stores system-dependent default name-separator character.static char separatorChar
stores system-dependent default name-separator character.
import java.io.File;
//from j ava2 s . c om
public class Main {
public static void main(String[] args) {
System.out.println(File.pathSeparator);
System.out.println(File.pathSeparatorChar);
System.out.println(File.separator);
System.out.println(File.separatorChar);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
- Is it a file or a directory
- Whether the file or directory denoted by this abstract pathname exists
- Is file hidden