【发布时间】:2014-05-07 11:14:41
【问题描述】:
我将 text1.txt 文件保存在与 Algo.java 文件所在的文件夹相同的文件夹中。但是我得到一个 Filenotfoundexception 并且我找不到任何原因。
import java.io.*;
import java.util.logging.Level;
java.util.logging.Logger;
public class Algo{
static void naive(){
BufferedReader file1;
try{
file1=new BufferedReader(new FileReader("text1.txt"));
String T=file1.readLine();
System.out.println(T);
}
catch (FileNotFoundException ex) {
Logger.getLogger(Algoq1.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Algoq1.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String args[]){
Algo.naive();
}
}
【问题讨论】:
-
您的 Algo.class 文件保存在哪里?尝试提供“text1.txt”文件的完整路径。你有什么包结构吗?
标签: java exception file-io bufferedreader filenotfoundexception