Java I/O How to - Get file system separator


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


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.