黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

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

使用Java文件登錄注冊

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

如何使用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
登錄成功
歡迎使用該應用程序。

 

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

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 黄色男女网站 | 免费观看呢日本天堂视频 | 色偷偷91久久综合噜噜噜噜 | 中国精品久久 | 成人在线免费视频播放 | 日韩 欧美 中文 | 日韩免费一区二区三区 | 欧美大片va欧美在线播放 | 成人午夜视频免费看欧美 | 亚洲欧美日本国产 | 最近最新中文字幕免费高清1 | 综合欧美日韩一区二区三区 | 欧美午夜性刺激在线观看免费 | 麻豆一区二区 | 国产在线精品一区免费香蕉 | 极品国产一区二区三区 | 五月婷婷丁香色 | 日韩黄色免费观看 | 正在播放的国产a一片 | 国产精品免费看久久久香蕉 | 午夜欧美精品久久久久久久久 | 五月婷婷丁香色 | 日韩成人黄色片 | 欧美色图一区 | 日韩欧美国产卡通动漫 | α片免费看 | 亚洲天堂网在线播放 | 91短视频版在线观看www免费 | 成人看片黄a免费 | 国产免费一区二区三区在线观看 | 香蕉视频啊啊啊 | 1024日本| 日本精品久久久免费高清 | 韩国伦理片在线看免 | 香港经典a毛片免费观看爽爽影院 | 九九九精品视频 | 日韩手机视频 | 国产欧美日韩网站 | 免费观看一级欧美大 | 在线网站黄色 | 免费看特黄特黄欧美大片 |