本人在info.data里保存拉用户的username和password,我怎样对其中的记录进行读取,,求高手指教!!要多少报酬也在所不惜!!

解决方案 »

  1.   

    info.data的结构是什么样子的?
    从文件读进来,再按结构找us和pw
      

  2.   

    用文件流写入文件,可以用如下方式获取:
    try
    {
    pro=new Properties();
    fr=getClass().getResourceAsStream("info.data");
    pro.load(fr);
    }
    catch(FileNotFoundException e){System.out.println(e);}String username=pro.getProperty("user");
    String psw=pro.getProperty("password");
      

  3.   

    我这里读取的代码没有实现循环,只能读取第一行,高手指点!!帖子完毕人人得分!!
      FileInputStream istream = new FileInputStream("userInfo.data");
      ObjectInputStream in = new ObjectInputStream(istream);
      UserInfo info = (UserInfo) in.readObject();
       if(txf_UserName.getText().equals(info.getUserName()) && tpf_Password.getText().equals     (info.getUserPassword())){
               yes = true;
             }
              istream.close();
    下面是info.data的添加行代码
     try{
              FileOutputStream ostream = new FileOutputStream("userInfo.data");
              ObjectOutputStream p = new ObjectOutputStream(ostream);
              UserInfo tmp = new UserInfo("x", "x");
              p.writeObject(tmp);
              tmp = new UserInfo("z", "z");
              p.writeObject(tmp);
              p.flush();
              ostream.close();
            } catch (IOException e) {}
      

  4.   

    例子里用的是Object的序列化,读写的是一整个对象,无须再循环什么的了。
      看样子username和userpassword都是UserInfo中的成员变量,类型是String
      要读取的话像上面例子中给的一样,读文件、取一个对象出来强制成UserInfo的对象,然后再通过getUserName()和getUserPassword()你想要的值:========
      FileInputStream istream = new FileInputStream("userInfo.data");
      ObjectInputStream in = new ObjectInputStream(istream);
      UserInfo info = (UserInfo) in.readObject();
      String username_I_want = info.getUserName();
      String password_I_want = info.getUserPassword();==========================
      

  5.   

    Any other question, please email to: [email protected]
                       or visit my blog: toppi.blogchina.com