How to read system directory and files in java code examples
import java.io.File;
public class TestDirReader{
public static void main(String[] args) {
File folder = new File("C://testDir");
File[] filesList= folder.listFiles();
for (int i = 0; i < filesList.length; i++) {
if (filesList[i].isDirectory()) {
System.out.println("Directory Name :" + filesList[i].getName());
}else if (filesList[i].isFile()) {
System.out.println("File Name :" + filesList[i].getName());
}
}
}
}
public class TestDirReader{
public static void main(String[] args) {
File folder = new File("C://testDir");
File[] filesList= folder.listFiles();
for (int i = 0; i < filesList.length; i++) {
if (filesList[i].isDirectory()) {
System.out.println("Directory Name :" + filesList[i].getName());
}else if (filesList[i].isFile()) {
System.out.println("File Name :" + filesList[i].getName());
}
}
}
}
Comments
Post a Comment