Display File class constants in Java


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();
}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

81 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements