我试图遍历整个路径及其单层子目录.对于每个文件,我需要读取五个数据字段并将它们输出到分隔的文本文件.我能够从单个文本文件中读取并在屏幕上验证我的输出; 之后我被卡住了.我似乎无法为FileVisit找到合适的参数.一些具体问题是我在下面发布的代码中的注释.虽然我不是那么远,但是我想知道写一个输出文件,即我希望把它放在哪个地方是最合乎逻辑的.
我已经在文件访问者http://docs.oracle.com/javase/7/docs/api/上查看了/sf/ask/693941/和JavaDocs的信息.
index.html?java/nio/file/FileVisitor.html.但是,我仍然无法让FileVisitor正常工作.
@Bohemian建议将interface到class,我所做的一切.
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 …Run Code Online (Sandbox Code Playgroud)