大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 Java學習 使用Java文件登錄注冊

使用Java文件登錄注冊

更新時間:2022-06-06 10:13:26 來源:動力節點 瀏覽1605次

如何使用Java文件登錄注冊?動力節點小編來告訴大家。

import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileWriter;
public class Registration {	
	private void register() throws FileNotFoundException
	{
		Scanner sc=new Scanner(System.in);		
		System.out.println("Enter User Name: ");
		String Uname=sc.nextLine();
		System.out.println(Uname);		
		System.out.println("Enter Password: ");
		String Pass=sc.nextLine();
		System.out.println(Pass);		
		System.out.println("Confirm Password: ");
		String ConPass=sc.nextLine();
		System.out.println(ConPass);
		Uname=Uname.trim();
		Pass=Pass.trim();
		ConPass=ConPass.trim();
		String x= Uname+" "+Pass;
		if(Pass.equals(ConPass))
		{			
			  File f = new File("Registration.txt");
		      Scanner content = new Scanner(f);		      		      
		      int flag=0;
		      while (content.hasNextLine()) {
		        String data = content.nextLine();
		        if(data.equals(x))
		        {
		        	System.out.println("Already Registered");
		        	flag=1;
		        	System.out.println("1. Registration. ");
					System.out.println("2. Login. ");					
					System.out.println("Enter your Choice");
					int choice=sc.nextInt();
					if(choice==1)
					{
						this.register();
					}
					else if(choice==2)
					{
						this.login();
					}
					else
					{
						System.out.println("Choose Proper Option");
					}
		        	break;
		        }
		        content.close();
		      }
		        if(flag==0)
		        {
		        	try {
			            BufferedWriter out = new BufferedWriter(new FileWriter("Registration.txt", true)); 
			            out.write(Uname+" "+Pass+"\n");
			            out.close();
			        }
			        catch (IOException e) {
			        	System.out.println("exception occoured" + e);
			        }
					
					System.out.println("Successfully Registered");
					System.out.println("Please login");
					this.login();
		        }						
		}
		else
		{
			System.out.println("Recheck");
			System.out.println("1. Registration. ");
			System.out.println("2. Login. ");			
			System.out.println("Enter your Choice");
			int choice=sc.nextInt();
			if(choice==1)
			{
				this.register();
			}
			else if(choice==2)
			{
				this.login();
			}
			else
			{
				System.out.println("Choose Proper Option");
			}
		}
		sc.close();
	}	
	public void login()
	{		
		Scanner sc=new Scanner(System.in);		
		System.out.println("Enter User Name: ");
		String Uname=sc.nextLine();
		System.out.println(Uname);		
		System.out.println("Enter Password: ");
		String Pass=sc.nextLine();
		System.out.println(Pass);
		Uname=Uname.trim();
		Pass=Pass.trim();
		String x= Uname+" "+Pass;				
		try {			
		      File f = new File("Registration.txt");
		      Scanner content = new Scanner(f);
		      int flag=0;
		      while (content.hasNextLine()) {
		        String data = content.nextLine();
		        if(data.equals(x))
		        {
		        	System.out.println("Login Successful");
		        	System.out.println("Welcome to the Application.");
		        	flag=1;
		        	break;
		        }
		      }
		        if(flag==0)
		        {
		        	System.out.println("Login Failed");
		        	System.out.println("1. Registration. ");
					System.out.println("2. Login. ");					
					System.out.println("Enter your Choice");
					int choice=sc.nextInt();
					if(choice==1)
					{
						this.register();
					}
					else if(choice==2)
					{
						this.login();
					}
					else
					{
						System.out.println("Choose Proper Option");
					}
		        }		      
		      content.close();
		    } 
			catch (FileNotFoundException e) {		    		    	
		      System.out.println("Error.");
		      e.printStackTrace();
		    }		
		sc.close();
	}	
	public static void main(String[] args) throws FileNotFoundException{
			try {			
		      File obj = new File("Registration.txt");		      
		      if (obj.createNewFile()) 
		      {
		        System.out.println("File is created");
		      } 		      
		    } 
			catch (IOException e) 
			{
		      System.out.println("An error occurred.");
		      e.printStackTrace();		      
		    }		
		int choice;
		Scanner sc=new Scanner(System.in);
		System.out.println("1. Registration. ");
		System.out.println("2. Login. ");		
		System.out.println("Enter your Choice");
		choice=sc.nextInt();
		sc.nextLine();		
		if(choice==1)
		{
			Registration user = new Registration();
			user.register();
		}
		else if(choice==2)
		{
			Registration user = new Registration();
			user.login();
		}
		else
		{
			System.out.println("Choose Proper Option");
		}
		sc.close();
	}	
}

輸出:

登記。
登錄。
輸入您的選擇
1
輸入用戶名:
Yash Jain
Yash Jain
輸入密碼:
abcd
abcd
確認密碼:
abcd
abcd
成功注冊
請登錄
輸入用戶名:
Yash Jain
Yash Jain
輸入密碼:
abcd
abcd
登錄成功
歡迎使用該應用程序。

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 中文字幕一级毛片视频 | 青青影院一区二区免费视频 | 国产精选在线播放 | 欧美成人高清免费大片观看 | 男人猛桶女人下面视频国产 | 久久骚 | 国产精品亚洲片在线牛牛影视 | 久久这里只有精品免费看青草 | 色婷婷综合在线视频最新 | 成人在线不卡视频 | 愉拍自拍| 国产亚洲综合色就色 | 日本一级毛片私人影院 | 国产成人毛片 | 国产欧美一区二区三区视频 | 国产精品久久久影院 | 久久中文字幕日韩精品 | 青娱乐伊人| 亚洲永久精品一区二区三区 | 国产成人在线视频观看 | 一区二区三| 国产精品一一在线观看 | 欧美爽爽| 亚洲精品国产第一区二区三区 | 久草手机视频在线 | 亚洲综合久久久久久888 | 日本精品久久久中文字幕 | 成人影院免费在线观看 | 成 人 免 费 黄 色 | 手机看片自拍日韩日韩高清 | 亚洲国产一区二区三区精品 | 亚洲综合区小说区激情区噜噜 | 国产欧美日韩高清专区手机版 | 精品久久亚洲一级α | 国产精品成人一区二区1 | jizz中国女人| 久久91亚洲精品久久91综合 | 欧美日韩国产亚洲一区二区三区 | 欧美久久一区二区三区 | 日韩黄色网页 | 亚洲精品免费日日日夜夜夜夜 |