zoukankan      html  css  js  c++  java
  • Java通过IO流输入输出 向文件中存入大量三个属性的值,并通过验证前两个属性输出第三个属性

     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	password	username"+"
    ");
    24             //换行
    25             out.write("23213	66yy	解饿"+"
    ");
    26             for(int j=0;j<100000;j++){
    27             int userid = randomInt();
    28             int password = randomInt();
    29             int username = randomInt();
    30             out.write(userid+"	"+password+"	"+username+"
    ");
    31             }
    32             out.write("2321sdf3	6fgds6yy	好就是解饿"+"
    ");
    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("	");
    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 }
  • 相关阅读:
    数据库分库分表
    工作笔记----数据库分表
    工作笔记----数据提取
    Runnable和Thread的应用场景
    LeetCode题目按公司分类
    spring boot Java配置搭建ssm (二)
    spring boot java配置搭建ssm 小案例(IDEA)
    spring boot xml配置搭建 ssm 小案例(IDEA)
    连接查询
    限定、模糊、排序、多表查询(3)
  • 原文地址:https://www.cnblogs.com/wangguoning/p/6262821.html
Copyright © 2011-2022 走看看