1 PackageObject.io;2 3 ImportJava.io.FileInputStream;4 Importjava.io.FileNotFoundException;5 ImportJava.util.Scanner;6 7 Public classLogin {8 Public Static voidMain (string[] args)throwsException {9Scanner sc=NewScanner (system.in);TenFileInputStream input=NewFileInputStream ("D:\\Program Files (x86) \\io\\login.txt"); One intLength=0; AString string=NULL; - - byte[] array=New byte[Input.available () +1024]; the while((Length=input.read (array))!=-1){ -string=NewString (array,0, length); - System.out.println (string); - } + -String[] Users=string.split ("&&");//Each person's login information is called a group + ASystem.out.println ("Please Enter account name:"); atString name=Sc.next (); - -System.out.println ("Please Enter password:"); -String pwd=Sc.next (); - //stitching the account password entered -String inputuser=name+ "," +pwd; in //loop Array to determine if there is a current account password - Booleanflag=false; to for(String u:users) { + if(Inputuser.equals (U)) { -SYSTEM.OUT.PRINTLN ("Login Successful"); theflag=true; * Break; $ }Panax Notoginseng } - //*********** the if(flag==false){ +System.out.println ("Failed"); A } the + - } $}
Read file in Java using input stream in IO stream to implement login function