Display File class constants in Java

Java 8Object Oriented ProgrammingProgramming

The java.io.File class has display constants File.separatorChar and File.pathSeparatorChar mainly. The File.separatorChar is ‘/’ and the File.pathSeparatorChar is ‘:’ for Unix.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.io.File;
public class Demo {
   public static void main(String[] args) {
      try {
         System.out.println("File.pathSeparatorChar = " + File.pathSeparatorChar);
         System.out.println("File.separatorChar = " + File.separatorChar);
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

The output of the above program is as follows −

Output

File.pathSeparatorChar = :
File.separatorChar = /

Now let us understand the above program.

The display constants File.separatorChar and File.pathSeparatorChar are printed. A code snippet that demonstrates this is given as follows −

try {
   System.out.println("File.pathSeparatorChar = " + File.pathSeparatorChar);
   System.out.println("File.separatorChar = " + File.separatorChar);
} catch(Exception e) {
   e.printStackTrace();
}
raja
Published on 25-Feb-2019 07:52:45
Advertisements