Advertisement
Guest User

Untitled

a guest
Jun 9th, 2021
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package com.delfrigon.learn;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.Locale;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.  
  11.  
  12.  
  13.         public static void main(String[] args) {
  14.  
  15.             Scanner userInput = new Scanner(System.in);
  16.  
  17.             try {
  18.                 File myObj = new File("filename.txt");
  19.                 if (myObj.createNewFile()) {
  20.                     System.out.println("File created: " + myObj.getName());
  21.                 } else {
  22.                     System.out.println();
  23.                 }
  24.             } catch (IOException e) {
  25.                 System.out.println();
  26.                 e.printStackTrace();
  27.             }
  28.  
  29.             System.out.println("Sign Up / Login?: ");
  30.             String signup = userInput.nextLine();
  31.             if (signup.equals("Sign Up")) {
  32.                 System.out.println("Select your new username: ");
  33.                 String usn = userInput.nextLine();
  34.                 System.out.println("Now enter your password!");
  35.                 String pwd = userInput.nextLine();
  36.  
  37.                 try {
  38.                     FileWriter myWriter = new FileWriter("filename.txt");
  39.                     myWriter.write("Username " + usn + "\n");
  40.                     myWriter.write("Password " + pwd + "\n");
  41.                     myWriter.close();
  42.                     if ("filename.txt".equals(usn)) {
  43.                         System.out.println("Choose another username or password.");
  44.                 } else {
  45.                         System.out.println("You has been successfully registered to ours system!");
  46.                     }
  47.  
  48.                 } catch (IOException e) {
  49.                     System.out.println("An error occurred.");
  50.                     e.printStackTrace();
  51.                 }
  52.             }
  53.             }
  54.  
  55.         }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement