how-to

File & Directory

How to get file separator

File separator is a char used for separate directory and file in paths. For this example you need to use:

import java.util.*;
import java.io.*;

VARIANT 1

Read it from java.io.File class.

System.out.println( File.separator );   // as string
System.out.println( File.separatorChar ); // as char

The output could be:

\
\

VARIANT 2

Read it from System class via property.

System.out.println( System.getProperty( "file.separator" ) );

The output could be:

\