File.pathSeparatorChar;
File.separatorChar;
The first statement prints "; (semicolon)" and the next prints "\ (backward slash)". They are used in setting the environment variables – classpath and path. They are operating system dependent. When a Java program is being executed, the programmer can obtain them by using the above static variables (not methods) of File class.
File file1 = new File("pqr.txt");
The file name whose metadata is to be obtained is passed as parameter to the File constructor. Infact, the File object file1 can be passed to FileInputStream and FileOutputStream constructors instead of direct file name.
All the methods of File class are self-explanatory.
getName() : Returns the name of the file
getPath() : Returns the classpath of the file
canRead() : Returns true the if the file can be read
canWrite() : Returns true if the file can be written
isFile() : Returns true if the parameter passed is a file
isDirectory() : Returns true if the parameter passed is a directory
lastModified() : Returns the file creation/latest modified time (which ever is latest) in seconds from epoch time (refer Calendar class)
length() : Returns the file in bytes
exists() : Returns true if the file exists in the current directory
explain The CLASSPATH Environment Variable
Whenever you load any software (like JDK, Tomcat etc.), you get two types files – executable files placed in bin folder and library files placed in lib folder. To recognize your software by the OS, set the address of bin folder in path and lib folder in classpath. path and classpath are known as environment variables.
What is environment variable?
It is a variable given by the OS to communicate with the running OS.