0

Java swing not read file in folder window server 2008 please help me.

 public void listFilesForFolder(final File folder) {
    for (final File fileEntry : folder.listFiles()) {
        if (fileEntry.isDirectory()) {
            listFilesForFolder(fileEntry);
        } else {
            System.out.println(fileEntry.getName());
        }
    }
}
final File folder = new File("C:\\folder_test");
listFilesForFolder(folder);
user3194852
  • 27
  • 2
  • 8
  • Are you getting any error ? If so share that also. – Arun Xavier Feb 26 '16 at 12:25
  • 1
    1) Since this is marked 'Swing' I'd suggest to get the directory from a `JFileChooser`. 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 3) Always copy/paste error and exception output! – Andrew Thompson Feb 26 '16 at 12:33
  • 1
    4) *"..please help me."* Please (form and) ask a question. – Andrew Thompson Feb 26 '16 at 12:34
  • I run the above code in the window server it does not work. – user3194852 Feb 26 '16 at 13:25
  • of course it doesn't work. There is no class, and there is code outside of a method – jhamon Feb 26 '16 at 13:26
  • *"I run the above code in the window server it does not work."* That tells us nothing that was not already obvious. Post an MCVE (that uses a file chooser). Copy/paste the stack trace. (Like I advised before you made that reply.) – Andrew Thompson Feb 26 '16 at 13:37

1 Answers1

-2

Here I found a solution, that should solve your problem:

 private BufferedReader br;

public ReadFileFromHardDrive() throws FileNotFoundException, IOException {
    String sCurrentLine;
    br = new BufferedReader(new FileReader("C:\\folder_test"));
    while ((sCurrentLine = br.readLine()) != null) {
        System.out.println(sCurrentLine);
    }
    br.close();
}

Here is some explanation:

Reading a plain text file in Java
How to read file in Java – BufferedReader

Community
  • 1
  • 1
Andy_Lima
  • 115
  • 10
  • 1
    are you just guessing what OP's problem is? OP did not ask a question nor explained his problem. He wrote a code that print each file names in a directory and subdirectory but you answer with a code that print a file content. – jhamon Feb 26 '16 at 13:00