当前位置: 代码迷 >> Java相关 >> 求帮助,GUI和文本读取的问题!~
  详细解决方案

求帮助,GUI和文本读取的问题!~

热度:284   发布时间:2012-05-02 13:18:41.0
求帮助,GUI和文本读取的问题!~
程序代码:
                                                         try{
                                                                   FileInputStream f=new  FileInputStream("d:/stu.txt");
                                                                   ObjectInputStream si=new ObjectInputStream(f);
                                                            
                                                                   for(int i=0;i<number;i++)
                                                                    {
                                                                       cust[i]=(Customer) si.readObject();
                                                                      System.out.println(cust[i]);
                                                                   }
                                                                   si.close();
                                                               }catch(Exception exc){}
                                                      
                                                                    for(int i=0;i<number;i++)
                                                                              {
                                                                                  if(custom.getCardN().equals(cust[i].getCardN()))
                                                                                   {
                                                                                        cust[i].setPassWrd(custom.getPassW());
                                                                                   }
                                                                          
                                                                              }
                                                                  
                                                                       
                                                                       
                                                           try{
                                                                  
                                                                          
                                                                        FileOutputStream f0=new  FileOutputStream("d:/stu.txt");
                                                                        ObjectOutputStream s0=new ObjectOutputStream(f0);
                                                                           for( Customer c:cust)
                                                                           {
                                                                               s0.writeObject(c);
                                                                               System.out.println(c);
                                                                           }
                                                                        
                                                                           s0.close();
                                                                  
                                                                }
                                                                  catch(Exception x){}      


我用GUI做了一个登录的图形界面。
用ObjectInputStream、ObjectOutputStream存取账户名和密码。
每次登录的时候账户名和密码都是从文本里面读取并比较。
初始化的时候:我是用ObjectOutputStream把对象数组读进文本的;
密码比较的时候 再把密码从文本读去出来。

问题出现在,我再设计一个修改密码的GUI的时候,用户名和密码也是从同一个文件读取的,我的目的是想让它读取读取的并保存我修改密码后的那个文本。
但是我成功对第2个用户进行成功修改后(第一个密码已经修改)再登录修改的第一个用户的时候就会就出现错误。就会回到是我之前初始化的文本。没有保存我修改密码后的那个文本。这是为什么呢?



----------------解决方案--------------------------------------------------------
  相关解决方案