首页 > 其他 > 详细

文件操作--文件内容-->字符串

时间:2019-12-11 22:32:54      阅读:77      评论:0      收藏:0      [点我收藏+]
import java.io.*;//https://my.oschina.net/u/3697586/blog/1601045
import java.util.*;
public class kkk
{
    public static void main(String[] args) 
    {
        Scanner In=new Scanner(System.in);
        System.out.println("请输入密码:");
        String pri_in=In.nextLine();
        File file = new File("D:/safety/safe.txt");
        //char[] tempchars = new char[50];
        //Reader in = null;
        //String str="";
        /*try {//将数组内容全部转换成字符串,含大量空格
            in = new InputStreamReader(new FileInputStream(file),"utf8");
            int i = 0;
            while ((i = in.read(tempchars)) != -1) {
                //System.out.println(tempchars);
                yanzheng=String.valueOf(tempchars);
            }
            //String yanzheng=String.valueOf(tempchars);
            System.out.print("yanzhen="+yanzheng);
            if(yanzheng.equals(pri_in)){
                System.out.println("验证通过");
            }
            else{
                System.out.println("验证失败");
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }*/
        try 
        {
            BufferedReader in = new BufferedReader(new FileReader(file));
            String str;
            while ((str = in.readLine()) != null) 
            {
                  //System.out.print(str);
                  if(str.equals(pri_in)){
                System.out.println("验证通过");
            }
                    else{
                System.out.println("验证失败");
                    }

            }
            in.close();
        } 
        catch (IOException e) 
        {
            e.getStackTrace();
        }
    }
}

文件操作--文件内容-->字符串

原文:https://www.cnblogs.com/DongChenYi/p/12025366.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!