1 package ABC1;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileReader;
6 import java.io.FileWriter;
7 import java.io.IOException;
8 import java.util.Random;
9
10 public class Filetest {
11
12 public static void main(String[] args) {
13 // TODO 自动生成的方法存根
14
15 try {
16 File file =new File("D:/textFile.txt");
17 if(!file.exists())
18 {
19 file.createNewFile();
20 }
21 FileWriter out = new FileWriter(file);
22 //往文件写入
23 out.write("userid\tpassword\tusername"+"\r\n");
24 //换行
25 out.write("23213\t66yy\t解饿"+"\r\n");
26 for(int j=0;j<100000;j++){
27 int userid = randomInt();
28 int password = randomInt();
29 int username = randomInt();
30 out.write(userid+"\t"+password+"\t"+username+"\r\n");
31 }
32 out.write("2321sdf3\t6fgds6yy\t好就是解饿"+"\r\n");
33 //刷新IO内存流
34 out.flush();
35 out.close();
36 //关闭
37 String temp=null;
38 int i =1;
39 BufferedReader in=new BufferedReader(new FileReader(file));
40 String rtn ="userid不正确" ;
41 while((temp=in.readLine())!=null)
42 {
43
44 if(temp.indexOf("451080121")!=-1)
45 {
46
47
48 String[] check = temp.split("\t");
49
50
51 if(check[1].equals("805786460"))
52 {
53 rtn="username="+check[2];
54 }
55 else
56 {
57 rtn="密码错误";
58 //System.out.println("密码错误");
59 }
60 }
61 }
62 System.out.println(rtn);
63
64 } catch (IOException e) {
65 // TODO 自动生成的 catch 块
66 e.printStackTrace();
67 }
68 }
69
70 public static int randomInt()
71 {
72 int rtn =0;
73 Random random = new Random();
74 rtn=random.nextInt(999999999)+10000;
75 return rtn;
76 }
77 }