-1

对不起可读性。堆栈似乎正在从代码行中修剪空格,并且没有显示缩进。哼。

这是打印到控制台没有任何问题......

CGT\whgdata\whnvp33.txt   << EXPECTED OUTPUT (excerpt)
CGT\whgdata\whnvt30.txt
CGT\whgdata\whnvt31.txt
CGT\whgdata\whnvt32.txt
CGT\whgdata\whnvt33.txt
CGT\whgdef.txt
CGT\whgdhtml.txt
CGT\whibody.txt
etc....

...直到我尝试将哈希表打印到文件中。从那时起,getFileListing不被识别为有效符号。

FileListing2.java:17: error: cannot find symbol
        List<File> files = FileListing2.getFileListing(startingDirectory);
  symbol:   method getFileListing(File)
  location: class FileListing2
1 error

有人可以借第二双眼睛来帮助我发现我意外/覆盖的内容。我敢肯定这是显而易见的。:\

import java.util.*;
import java.io.*;
import java.nio.*;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption.*;
import java.nio.file.Paths;
//
public final class FileListing2 {
    public static void main(String... aArgs) {
//
    File startingDirectory= new File("CGT");
    File outputFile = new File("CGTOutput.txt");
    List<File> files = FileListing2.getFileListing(startingDirectory);
    OutputStream output = null;
    //
    for(File file : files )        {
       System.out.println(file);  //print filenames
    }
}
}
4

2 回答 2

2

是的,这是非常令人讨厌的事情,您的课程FileListing2不包含方法getFileListing(File)。它必须是静态的,就像您尝试调用它的方式一样:

public final class FileListing2 {
    public static void main(String... aArgs) {
        //
        File startingDirectory= new File("CGT");
        File outputFile = new File("CGTOutput.txt");
        List<File> files = FileListing2.getFileListing(startingDirectory);
        OutputStream output = null;
        //
        for(File file : files ) {
            System.out.println(file);  //print filenames
        }
    }
    public static List<File> getFileListing(File f) {
    /* implementation */
    }
}
于 2012-05-01T11:47:52.927 回答
2

如果你的代码就是你所拥有的FileListing2,那么就没有getFileListing()方法LileListing2,只有main()方法

于 2012-05-01T11:48:10.010 回答