This section demonstrates you the use of file separator.
A file separator is a character that is used to separate directory names that make up a path to a particular location. It is operating system dependent. On Microsoft Windows, it is a back-slash character (\) while on Mac OS and unix based operating system, it is forward slash(/). By using the file.separator key from the system property, you can avoid checking for the OS.
In the given example, we have used file.separator to make up a path.
Here is the code:
import java.io.*;
public class PathSeparator {
public static void main(String[] args) {
String path = "C:";
String pathSep = path + File.separator + "Hello" + File.separator;
System.out.println(pathSep);
}
}
Output:
| C:\Hello\ |