Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Demo {
- public static void main(String[] args) {
- int chon;
- menu();
- Scanner s = new Scanner(System.in);
- do {
- System.out.println("Nhap menu: ");
- chon = s.nextInt();
- switch (chon) {
- case 1:
- System.out.println("Thoat");
- break;
- case 2:
- CreateAccount();
- break;
- case 3:
- Display();
- break;
- case 4:
- Login();
- break;
- default:
- System.out.println("Chon sai");
- break;
- }
- } while (chon != 1);
- }
- public static void menu() {
- System.out.println("1. Thoat");
- System.out.println("2. Đăng ký tài khoản");
- System.out.println("3. Xem thông tin tài khoản");
- System.out.println("4. Dang nhap vao tai khoan");
- }
- public static void CreateAccount() {
- String user, password;
- System.out.println("Dang ky tai khoan");
- System.out.print("Nhap user Account: ");
- Scanner s = new Scanner(System.in);
- user = s.nextLine();
- System.out.print("Nhap pass Account: ");
- Scanner s1 = new Scanner(System.in);
- password = s1.nextLine();
- try {
- FileOutputStream fos = new FileOutputStream("login.txt");
- fos.write(user.getBytes());
- fos.write(password.getBytes());
- fos.close();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void Login() {
- String user1, password1;
- System.out.println("Nhap thong tin dang nhap");
- System.out.print("Nhap User: ");
- Scanner s = new Scanner(System.in);
- user1 = s.nextLine();
- System.out.print("Nhap Password: ");
- Scanner s2 = new Scanner(System.in);
- password1 = s2.nextLine();
- try {
- BufferedReader br = new BufferedReader(new FileReader("login.txt"));
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void Display() {
- String u = null, p = null;
- try {
- BufferedReader br = new BufferedReader(new FileReader("login.txt"));
- u = br.readLine();
- p = br.readLine();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
- }
- System.out.println("Thong tin dang nhap");
- System.out.println("User: " + u);
- System.out.println("Password: " + p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement