- File.separator == > separator: Platform dependent default name-separator character as String. For windows, it’s ‘\’ and for unix it’s ‘/’.
- File.separatorChar ==>separatorChar: Same as separator but it’s char.
- File.pathSeparator ==> pathSeparator: Platform dependent variable for path-separator. For example PATH or CLASSPATH variable list of paths separated by ‘:’ in Unix systems and ‘;’ in Windows system.
- File.pathSeparatorChar ==> pathSeparatorChar: Same as pathSeparator but it’s char.
- This is the environment independent property.This will be usefull for file upload and downloading etc.
- package commonsUtils;
- import java.io.File;
- public class FileSep{
- public static void main(String[] args){
- String filepath = File.separator + "sample" + File.separatorChar + "seperator";
- String pathSep = File.pathSeparator + "sample" + File.pathSeparatorChar + "seperator";
- System.out.println("The path of the file is : " + filepath);
- System.out.println("The path of the file is : " + pathSep);
- System.out.println("File.separator = "+File.separator)
- System.out.println("File.separatorChar = "+File.separatorChar);
- System.out.println("File.pathSeparator = "+File.pathSeparator);
- System.out.println("File.pathSeparatorChar = "+File.pathSeparatorChar);
- }
- }
Output :
For Windows
-------------
The path of the file is : \sample\seperator
The path of the file is : ;sample;seperator
File.separator = \
File.separatorChar = \
File.pathSeparator = ;
File.pathSeparatorChar = ;
For Unix
----------
The path of the file is : /sample/seperator
The path of the file is : :sample:seperator
File.separator = /
File.separatorChar = /
File.pathSeparator = :
File.pathSeparatorChar = :
No comments:
Post a Comment