Java I/O How to - Get file system separator








Question

We would like to know how to get file system separator.

Answer

import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
//from w  w w.  ja v  a  2s  .  c  o m
public class Main {

  public static void main(String[] args) throws Exception {
    String separator;
    separator = FileSystems.getDefault().getSeparator();
    System.out.println("The separator is " + separator);

  }
}

The code above generates the following result.