0
Java Read all files in drive C
how to read all files stocked in drive c with java
5 Answers
+ 6
Below example shows how to get list of all file objects from the given folder. First create File object by passing folder path. Call listFiles() method on file object to get list of file names in the given folder.
package com.java2novice.files;
Â
import java.io.File;
Â
public class FilesListFromFolder {
    Â
    public static void main(String a[]){
        File file = new File("C:/MyFolder/");
        File[] files = file.listFiles();
        for(File f: files){
            System.out.println(f.getName());
        }
    }
}
0
thank you but this read only specific folder , I wish read folder and sub folders
0
What you intend to do by reading all files in each directories?
0
for tutorial
0
There are factors to consider, for example, file system objects (files, directories) in modern O/Ses may be encrypted or compressed by system to prevent unauthorized access. And next, there are antivirus programs, which may presume your program was doing some aggresive action (read all files) and may take actions in attempt to keep safe the system.
I'm not trying to stop you in your way, just giving you a little points to consider.
If you can get Bruno's code to run, then you can turn it into a recursive function, which you can try as a test.
Anyways, good luck buddy! đ