Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.delfrigon.learn;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Locale;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner userInput = new Scanner(System.in);
- try {
- File myObj = new File("filename.txt");
- if (myObj.createNewFile()) {
- System.out.println("File created: " + myObj.getName());
- } else {
- System.out.println();
- }
- } catch (IOException e) {
- System.out.println();
- e.printStackTrace();
- }
- System.out.println("Sign Up / Login?: ");
- String signup = userInput.nextLine();
- if (signup.equals("Sign Up")) {
- System.out.println("Select your new username: ");
- String usn = userInput.nextLine();
- System.out.println("Now enter your password!");
- String pwd = userInput.nextLine();
- try {
- FileWriter myWriter = new FileWriter("filename.txt");
- myWriter.write("Username " + usn + "\n");
- myWriter.write("Password " + pwd + "\n");
- myWriter.close();
- if ("filename.txt".equals(usn)) {
- System.out.println("Choose another username or password.");
- } else {
- System.out.println("You has been successfully registered to ours system!");
- }
- } catch (IOException e) {
- System.out.println("An error occurred.");
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement