我是想用序列化对文件读写的,之前的保存写入文件都没问题 但是删除这就不行 帮忙看下把
这是删除代码
public void delete(User user){
try {
ods = new ObjectOutputStream(new FileOutputStream("config/telephone.txt"));
lstUsers=this.getUsers();//执行到这行事跳转到下面
List<User> tmp = new ArrayList<User>();
for( int i= 0;i < lstUsers.size();i++){
if(lstUsers.get(i).getNo()!=user.getNo()){
tmp.add(lstUsers.get(i)) ;
}
}
ods.writeObject(tmp);
ods.flush();
ods.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public List<User> getUsers(){
try {
ois = new ObjectInputStream(new FileInputStream("config/telephone.txt"));
lstUsers = (ArrayList<User>)ois.readObject();//在这里就停止了【!!】
ois.close();
}
catch(Exception e){
intRecord();//发生异常重新创建
}
// catch(FileNotFoundException e){
// intRecord();
// }
// catch (ClassNotFoundException e) {
// e.printStackTrace();
// }
// catch (IOException e) {
// e.printStackTrace();
// }
return lstUsers;
}在【!!】位置,我之前调试到这就说SOURCE NOT FOUND 可是我之前保存对象时也用了这个函数 但没有任何问题 求助!
这是删除代码
public void delete(User user){
try {
ods = new ObjectOutputStream(new FileOutputStream("config/telephone.txt"));
lstUsers=this.getUsers();//执行到这行事跳转到下面
List<User> tmp = new ArrayList<User>();
for( int i= 0;i < lstUsers.size();i++){
if(lstUsers.get(i).getNo()!=user.getNo()){
tmp.add(lstUsers.get(i)) ;
}
}
ods.writeObject(tmp);
ods.flush();
ods.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public List<User> getUsers(){
try {
ois = new ObjectInputStream(new FileInputStream("config/telephone.txt"));
lstUsers = (ArrayList<User>)ois.readObject();//在这里就停止了【!!】
ois.close();
}
catch(Exception e){
intRecord();//发生异常重新创建
}
// catch(FileNotFoundException e){
// intRecord();
// }
// catch (ClassNotFoundException e) {
// e.printStackTrace();
// }
// catch (IOException e) {
// e.printStackTrace();
// }
return lstUsers;
}在【!!】位置,我之前调试到这就说SOURCE NOT FOUND 可是我之前保存对象时也用了这个函数 但没有任何问题 求助!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货