Home Tutorial Java Core Files Java file separator

 
 

Java file separator
Posted on: June 5, 2006 at 12:00 AM
Advertisement
This section demonstrates you the use of file separator.

Java file separator

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\
Advertisement

Related Tags for Java file separator:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 5, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com