Advertisement
anhit92

Demo

Jun 12th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileOutputStream;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.util.Scanner;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. public class Demo {
  13.  
  14. public static void main(String[] args) {
  15. int chon;
  16. menu();
  17. Scanner s = new Scanner(System.in);
  18. do {
  19. System.out.println("Nhap menu: ");
  20. chon = s.nextInt();
  21. switch (chon) {
  22. case 1:
  23. System.out.println("Thoat");
  24. break;
  25. case 2:
  26. CreateAccount();
  27. break;
  28. case 3:
  29. Display();
  30. break;
  31. case 4:
  32. Login();
  33. break;
  34. default:
  35. System.out.println("Chon sai");
  36. break;
  37. }
  38. } while (chon != 1);
  39. }
  40.  
  41. public static void menu() {
  42. System.out.println("1. Thoat");
  43. System.out.println("2. Đăng ký tài khoản");
  44. System.out.println("3. Xem thông tin tài khoản");
  45. System.out.println("4. Dang nhap vao tai khoan");
  46. }
  47.  
  48. public static void CreateAccount() {
  49. String user, password;
  50. System.out.println("Dang ky tai khoan");
  51. System.out.print("Nhap user Account: ");
  52. Scanner s = new Scanner(System.in);
  53. user = s.nextLine();
  54.  
  55. System.out.print("Nhap pass Account: ");
  56. Scanner s1 = new Scanner(System.in);
  57. password = s1.nextLine();
  58. try {
  59. FileOutputStream fos = new FileOutputStream("login.txt");
  60. fos.write(user.getBytes());
  61. fos.write(password.getBytes());
  62. fos.close();
  63. } catch (FileNotFoundException ex) {
  64. Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
  65. } catch (IOException ex) {
  66. Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
  67. }
  68. }
  69.  
  70. public static void Login() {
  71. String user1, password1;
  72. System.out.println("Nhap thong tin dang nhap");
  73. System.out.print("Nhap User: ");
  74. Scanner s = new Scanner(System.in);
  75. user1 = s.nextLine();
  76.  
  77. System.out.print("Nhap Password: ");
  78. Scanner s2 = new Scanner(System.in);
  79. password1 = s2.nextLine();
  80. try {
  81. BufferedReader br = new BufferedReader(new FileReader("login.txt"));
  82. } catch (FileNotFoundException ex) {
  83. Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
  84. }
  85. }
  86.  
  87. public static void Display() {
  88. String u = null, p = null;
  89. try {
  90. BufferedReader br = new BufferedReader(new FileReader("login.txt"));
  91. u = br.readLine();
  92. p = br.readLine();
  93. } catch (FileNotFoundException ex) {
  94. Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
  95. } catch (IOException ex) {
  96. Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
  97. }
  98. System.out.println("Thong tin dang nhap");
  99. System.out.println("User: " + u);
  100. System.out.println("Password: " + p);
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement