@g5orge

Хотел сделать что то типо авторизации. Что я делаю не так?

package main;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Formatter;
import java.util.Scanner;

public class FileTest {
	static Scanner v;
	static Formatter f;
	public static void main(String[] args) {
		String db = new File("text.txt").getAbsolutePath();
		System.out.println(db);
		File db2 = new File(db);
		try {
			f = new Formatter(db2);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			System.err.println("error! file not found");
			System.err.println("creating file...");
			try {
				boolean isCreated = db2.createNewFile();
				if(isCreated)
					System.out.println("File Created!");
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				System.err.println("error creating file!");
				e1.printStackTrace();
			}
		}
		 static void startnow() {
			try {
				String db3 = new File("text.txt").getAbsolutePath();
				File db23 = new File(db);
				v = new Scanner(db2);
			} catch (FileNotFoundException e12) {
				// TODO Auto-generated catch block
				System.err.println("error! file still not found");
			}
			String[] inp;
			try {
				String db1 = new File("text.txt").getAbsolutePath();
				File db21 = new File(db);
				v = new Scanner(db2);
			} catch (FileNotFoundException e13) {
				// TODO Auto-generated catch block
				e13.printStackTrace();
			}
			String p = v.nextLine();
			inp = p.split(":");
			System.out.println(inp.length);
			if(inp[0] == null) { System.out.println("not registered");
			System.out.println("Please Register. Enter your login ");
			Scanner inp2 = new Scanner(System.in);
			String login = inp2.nextLine();
			System.out.println("Enter Password");
			String pass = inp2.nextLine();
			f.format("%s:%s", login, pass); }
			else { System.out.println("You are registered");
			System.out.println("Please enter your login");
			Scanner inp2 = new Scanner(System.in);
			String llogin = inp2.nextLine();
			System.out.println("Enter pass");
			String lpass = inp2.nextLine();
			if(inp[0].equals(llogin) && inp[1].equals(lpass)) System.out.println("You Logged In!");
			else if (inp[0].equals(llogin) || inp[1].equals(lpass)) System.out.println("Wrong login or pass!");
			}
		}
} }
Что я делал не так?
  • Вопрос задан
  • 101 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы