I am trying to step through an entire path and its single layer of sub directories. For each file, I need to read five data fields and output them to a delimited text file. I'm able to read from a single text file and validate my output on screen; after that I'm stuck. I cannot seem to to find the right parameters for FileVisit. Some specific questions are comments in my code posted below. And although I'm no nearly that far yes, I'd like to get some idea for writing to an output file, namely whether the place I wish to put it is the most logical one.
I've reviewed the https://stackoverflow.com/questions/9913/java-file-io-compendium and JavaDocs' info on the File Visitor
http://docs.oracle.com/javase/7/docs/api/index.html?java/nio/file/FileVisitor.html .
However, I'm still not able to get FileVisitor working properly.
@Bohemian suggested changing interface
to class
which I've done.
import java.nio.files.*;
public class FileVisitor<T>
{
Path startPath = Paths.get("\\CallGuidesTXT\\");
Files.walkFileTree(startPath, new SimpleFileVisitor(startPath))
\\ ^^^^^^
\\ errors out, <identifier expected>
{
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException
{
Files.list(file);
return FileVisitResult.CONTINUE;
}
// do my file manipulations here, then write the delimited line
// of text to a CSV fle...is this the most appropriate place for that
// operation in this sample?
}
}
SSCCE below...but comments in the version above point to specific questions I'm having.
import java.nio.*;
import java.util.*;
public class FileVisitor<T>
{
Path startPath = Paths.get("\\CallGuidesTXT\\");
}
Files.walkFileTree(startPath, new SimpleFileVisitor(startPath) {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.list(file);
return FileVisitResult.CONTINUE;
}
});