import java.io.*;
class OneDeposit{
String[] info=new String[9]; //声明存储储户信息的数组
OneDeposit(){}
public OneDeposit(String number,String name,String password,String capital,
String sort,String saveDay,String address,String saveAssistant,String isLost){
info[0]=number; info[1]=name; info[2]=password;
info[3]=capital; info[4]=sort; info[5]=saveDay;
info[6]=address; info[7]=saveAssistant; info[8]=isLost;
}
void createFiles()throws IOException{
File f=new File("存款文件.dat");
if(!f.exists()){
BufferedWriter out=new BufferedWriter(new FileWriter("存款文件.dat"));
out.close();
}
}
void write(BufferedWriter out)throws IOException{
for(int i=0;i<9;i++){
out.write(this.info[i]);
out.newLine();
}
}
int search(BufferedReader in,String number)throws IOException{
int line=0,i;
while(in.readLine()!=null){line++;}
String[][] info2=new String[line/9][9];
for(int a=0;a<info2.length;a++){
for(int b=0;b<info2[a].length;b++){
info2[a]=in.readLine();
}
}
//测试区
for(int c=0;c<info2.length;c++){
for(int d=0;d<info2[c].length;d++){System.out.println(info2[c][d]);}
}
for(i=0;i<info2.length;i++){
if(info2[i].equals(number)) {
for(int j=0;j<9;j++){info[j]=info2[i][j];}
return 1;
}
}
return -1;
}
}
public class TestOneDeposit{
public static void main(String[] args){
OneDeposit d1=new OneDeposit();
d1.info[0]="19860923";
d1.info[1]="李四";
d1.info[2]="abcdef";d1.info[3]="65300";d1.info[4]="三年";
d1.info[5]="20041001";d1.info[6]="中华人民共和国";
d1.info[7]="混蛋007";d1.info[8]="false";
for(int j=0;j<9;j++){System.out.println(d1.info[j]+" ");}
try{
BufferedWriter out=new BufferedWriter(new FileWriter("存款文件.dat",true));
d1.write(out);
}catch(IOException el){System.out.println(el);}
try{
BufferedReader in=new BufferedReader(new FileReader("存款文件.dat"));
OneDeposit d2=new OneDeposit();
int k=d2.search(in,"19860923");
for(int j=0;j<9;j++){System.out.println(d2.info[j]+" ");}
}catch(IOException e){}
}
}
又试着写了一个这样的程序,还是没用啊~~~~急噪咯!