1 package object.io; 2 3 import java.io.FileInputStream; 4 import java.io.FileNotFoundException; 5 import java.util.Scanner; 6 7 public class Login { 8 public static void main(String[] args) throws Exception { 9 Scanner sc=new Scanner(System.in); 10 FileInputStream input=new FileInputStream("D:\\Program Files (x86)\\io\\login.txt"); 11 int length=0; 12 String string=null; 13 14 byte[] array=new byte[input.available()+1024]; 15 while((length=input.read(array))!=-1){ 16 string=new String(array,0,length); 17 System.out.println(string); 18 } 19 20 String[] users=string.split("&&");//每个人的登录信息称为一组 21 22 System.out.println("请输入账户名:"); 23 String name=sc.next(); 24 25 System.out.println("请输入密码:"); 26 String pwd=sc.next(); 27 //拼接输入的账号密码 28 String inputUser=name+","+pwd; 29 //循环数组判断是否有当前账号密码 30 boolean flag=false; 31 for(String u:users){ 32 if(inputUser.equals(u)){ 33 System.out.println("登录成功"); 34 flag=true; 35 break; 36 } 37 } 38 //*********** 39 if(flag==false){ 40 System.out.println("失败"); 41 } 42 43 44 } 45 }