[英]How to compare username password and secret code with text file to login java
Below my code is only to input data into text file now i have to make a new login form when user put username password and secret code it will logged in if wrong then error i put some data in text file using code below now i want to compare from text file and logged in i am making a java program on sublime i am newbie this is my assignment how to compare in simplest way with text file data, text file contains username password secret code in same line how to arrange that i am stuck i am trying from last 9 hours its assignment 我的代码下面仅是将数据输入文本文件中,现在我必须在用户输入用户名密码和密码时制作一个新的登录表单,如果输入错误然后将出错,我将使用下面的代码在文本文件中输入一些数据。从文本文件比较并登录我正在升华制作Java程序我是新手,这是我的工作如何以最简单的方式与文本文件数据进行比较,文本文件在同一行中包含用户名密码秘密代码如何安排我被卡住我正在尝试从过去的9个小时开始
import java.util.*;
import java.io.*;
public class Reg{
public static void main (String[]args)throws IOException {
Users p = new Users();
Scanner sc = new Scanner(System.in);
System.out.println("Enter username");
String uu = sc.nextLine();
p.setUser(uu);
System.out.println("Enter password");
String pp = sc.nextLine();
p.setPassword(pp);
System.out.println("Enter Secret number");
String ss = sc.nextLine();
p.setSecret(ss);
FileWriter fw = new FileWriter(file);
PrintWriter pw = new PrintWriter(fw);
pw = new PrintWriter(new FileWriter("output.txt", true));
pw.write(uu);
pw.write(pp);
pw.write(ss);
pw.close();
}
}
You already created the pw, don't need to create again and i write something in the code you read from it. 您已经创建了pw,不需要再次创建,并且在您从中读取的代码中写了一些东西。 I wish it will help you.
希望对您有帮助。
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JFrame;
public class Reg{
public static void main (String[]args)throws IOException {
Users p = new Users();
String uu = "";
String pp = "";
String ss = "";
//I think you created a method in Users and say logined or something error.
While(Users.getLogin == false){
//***I don't know the Users class you made
Scanner sc = new Scanner(System.in);
System.out.println("Enter username");
uu = sc.nextLine();
p.setUser(uu);
System.out.println("Enter password");
pp = sc.nextLine();
p.setPassword(pp);
System.out.println("Enter Secret number");
ss= sc.nextLine();
p.setSecret(ss);
}
//Something like this
if(Users.getLogin == true){
//if you wanna write something to the file, u can use this.
FileWriter fw = new FileWriter("output.txt");
PrintWriter pw = new PrintWriter(fw);
pw.write(uu);
pw.write(pp);
pw.write(ss);
//if you wanna write line by line use writeln, not write.
pw.close();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.