File across Operating System

In this chapter you will learn:

  1. Use system dependent path/name separator

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:

  1. Is it a file or a directory
  2. Whether the file or directory denoted by this abstract pathname exists
  3. Is file hidden
Home » Java Tutorial » File
File
File across Operating System
File properties
File creation
File path
File path compare
File delete
File parent folder
File drive root
File size/length
File new directories
File rename
File modified time
File executable, readable or writable
File location to URI
File copy