我无法在这里找到我的代码有什么问题
public class Library{
FileReader fr = new FileReader("D:\\Users\\Adi\\Documents\\NetBeansProjects\\Hw 7Jan-13Jan\\Date.txt");
BufferedReader br = new BufferedReader(fr);
public void add(Publication p){
if(counter < publication.length){
publication[counter++]=p;
}
}
public boolean remove(int id){
Publication p=null;
for(int i=0;i<counter;i++)
if(publication[i].getId()==id){
p=publication[i];
for(int j=0;j<counter-1;j++)
publication[j]=publication[j+1];
publication[counter-1]=null;
counter--;
return true;
}
return false;}
}
我尝试使用try{}
catch{}
,但后来又出现了其他错误:class,interface or enum expected
感谢任何帮助!谢谢
P.S:我是这个IOException的新手并尝试{} catch {}:)
答案 0 :(得分:0)
static{
try {
FileReader fr = new FileReader("D:\\Users\\Adi\\Documents\\NetBeansProjects\\Hw 7Jan-13Jan\\Date.txt");
} catch (Exception e) {
}
}
或在Constructor中分配FileReader。
FileReader fr;
public Library(){
try {
fr = new FileReader("D:\\Users\\Adi\\Documents\\NetBeansProjects\\Hw 7Jan-13Jan\\Date.txt");
} catch (Exception e) {
}
BufferedReader br = new BufferedReader(fr);
}