62,614
社区成员
发帖
与我相关
我的任务
分享
public String readFile(String title){
String info;
FileReader fr;
try{
fr = new FileReader(path + title + ".txt");
}catch(FileNotFoundException e){
return ""; //注意这里
}
BufferedReader br = new BufferedReader(fr);
try{
info = br.readLine();
br.close();
fr.close();
}catch(IOException e){
return null; //注意这里
}
return info;
}
public String readFile(String title){
String info;
FileReader fr;
try{
fr = new FileReader(path + title + ".txt"); //提示fr没有被初始化
}catch(FileNotFoundException e){
e.printStackTrace(); //这里和上面的不同
}
BufferedReader br = new BufferedReader(fr);
try{
info = br.readLine();
br.close();
fr.close();
}catch(IOException e){
e.printStackTrace(); //这里和上面的不同
}
return info; //提示info没有被初始化
}