//注册
@Override
public boolean regist(User user) {
boolean flag = false;
//高效字符输入流
BufferedWriter bw = null ;
BufferedReader br = null;
try {
bw = new BufferedWriter(new FileWriter("user.txt",true));//追加写
br = new BufferedReader(new FileReader("user.txt"));
//封装用户数据
String userInfo = user.getUserName()+"="+user.getPassword();
//写入
//一次读取一行
String line = null;
if(br.readLine() == null){
bw.write(userInfo);
//换行
bw.newLine();
//刷新
bw.flush();
flag = true;
return flag;
}
while((line = br.readLine()) != null){
if(!userInfo.equals(line)){
bw.write(userInfo);
//换行
bw.newLine();
//刷新
bw.flush();
flag = true;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if(bw != null & br != null){
try {
bw.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return flag;
}
在注册工程中,当再次注册新用户时,不能把注册信息添加到user.txt文档里面,是什么原因啊
|
|