Code
----------
import java.io.File;
class GetLocalDrives {
public static void main(String args[]) {
File[] f = File.listRoots();
for (File k : f)
System.out.println(k);
System.out.println("The file separator is " + File.separatorChar);
}
}
Sample output
------------------
C:\
D:\
E:\
F:\
H:\
The file separator is \
Explanation
----------------
listRoots(): It is a static method of the java.io.File class and is used to get all the roots (local drives).
Note: The file separator depends upon your OS. If windows \ is the output, for linux like OS / is the file separator.
----------
import java.io.File;
class GetLocalDrives {
public static void main(String args[]) {
File[] f = File.listRoots();
for (File k : f)
System.out.println(k);
System.out.println("The file separator is " + File.separatorChar);
}
}
------------------
C:\
D:\
E:\
F:\
H:\
The file separator is \
Explanation
----------------
listRoots(): It is a static method of the java.io.File class and is used to get all the roots (local drives).
Note: The file separator depends upon your OS. If windows \ is the output, for linux like OS / is the file separator.
No comments:
Post a Comment