FileSystem getSeparator() method in Java with Examples
Last Updated :
02 Aug, 2021
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
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
{
Path path
= Paths.get(
"C:\\Movies\\document.txt" );
FileSystem fs = path.getFileSystem();
String separator = fs.getSeparator();
System.out.println( "Separator: "
+ separator);
}
}
|
Output:
Program 2:
Java
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
public static void main(String[] args)
{
Path path
= Paths.get(
"E:// Tutorials// file.txt" );
FileSystem fs = path.getFileSystem();
String separator = fs.getSeparator();
System.out.println( "File Separator: "
+ separator);
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...