Open In App

FileSystem getSeparator() method in Java with Examples

Last Updated : 02 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The getSeparator() method of a FileSystem class is used to return the name separator for this file system as a string. The name separator is used to separate names in a path string. In the case of the default provider, this method returns the same separator as String.
Syntax: 
 

public abstract String getSeparator()


Parameters: This method accepts nothing.
Return value: This method returns the same separator as String.
Below programs illustrate the getSeparator() method: 
Program 1: 
 

Java
// Java program to demonstrate
// FileSystem.getSeparator() method

import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;

public class GFG {

    public static void main(String[] args)
    {

        // create the object of Path
        Path path
            = Paths.get(
                "C:\\Movies\\document.txt");

        // get FileSystem object
        FileSystem fs = path.getFileSystem();

        // apply getSeparator() methods
        String separator = fs.getSeparator();

        // print
        System.out.println("Separator: "
                           + separator);
    }
}

Output: 
 


Program 2: 
 

Java
// Java program to demonstrate
// FileSystem.getSeparator() method

import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;

public class GFG {

    public static void main(String[] args)
    {

        // create the object of Path
        Path path
            = Paths.get(
                "E:// Tutorials// file.txt");

        // get FileSystem object
        FileSystem fs = path.getFileSystem();

        // apply getSeparator() methods
        String separator = fs.getSeparator();

        // print
        System.out.println("File Separator: "
                           + separator);
    }
}

Next Article

Similar Reads