Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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();
}Advertisements