Read file in Java using input stream in IO stream to implement login function

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.