谢谢家伙解决了我的第一个问题,我现在遇到了一个新错误
import java.io.*;
import javax.swing.*;
public class FileBrowser {
public static void main(String[] args) throws IOException {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
String filename = file.getName();
System.out.println("You have selected: " + filename);
FileReader fr = new FileReader("filename");
BufferedReader br = new BufferedReader(fr);
String s;
while((s = br.readLine()) != null) {
System.out.println(s);
}
fr.close();
}
}
错误 :
java.io.FileNotFoundException: filename (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at java.io.FileReader.<init>(FileReader.java:58)
at FileBrowser.main(FileBrowser.java:13)
是没有从文件浏览器正确获取文件名的错误吗?