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.
Below is the example of File.separator
package com.java.everythingaboutselenium;
import java.io.File;
import java.io.IOException;
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\
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.
Below is the example of File.separator
package com.java.everythingaboutselenium;
import java.io.File;
import java.io.IOException;
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\