-2

I have a similar problem to this question, and I tried the answer that the question accepted:

File folder = new File("/path/to/files");
File[] listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
  File file = listOfFiles[i];
  if (file.isFile() && file.getName().endsWith(".txt")) {
    String content = FileUtils.readFileToString(file);
    /* do somthing with content */
  } 
}

Only when I tried compiling, it couldn't find the variable FileUtils. Is there a java package that I have to import at the beginning of my program to use class File methods? I've never used File objects before, so I'm trying to learn to be able to work with and manipulate them. Thanks.

Community
  • 1
  • 1
keenns
  • 863
  • 4
  • 14
  • 26
  • 1
    FileUtils is from Apache Commons IO library & to use FileUtils you need this jar file .Then import org.apache.commons.io.FileUtils to your class. – Ashok_Pradhan Jun 09 '14 at 04:21

2 Answers2

0

This is Apache Commons FileUtils . http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html

You would need to import import org.apache.commons.io.FileUtils;

Devesh
  • 2,024
  • 2
  • 16
  • 21
0
http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html 

Check here for file file utils.

Raj
  • 942
  • 1
  • 7
  • 12