package com.zhidi.properties;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
System.out.println("=======欢迎登录========");
Scanner sc=new Scanner(System.in);
System.out.println("请输入用户名");
String name=sc.next();
System.out.println("请输入密码");
String pwd=sc.next();
yanzheng(name,pwd);
}
public static void yanzheng(String name,String pwd) throws IOException{
//1.实例化properties对象
Properties prop = new Properties();
//2.获得属性文件
FileInputStream fis = new FileInputStream("F:\\stu.properties");
//3.使用属性对象的load()方法获取内容
prop.load(fis);
//4.根据键获得值
String userName = prop.getProperty("userName");
String userpwd = prop.getProperty("pwd");
if(name.equals(userName)){
if(pwd.equals(userpwd)){
System.out.println("登录成功!");
}else{
System.out.println("密码错误!");
}
}else{
System.out.println("账号不存在!");
}
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
System.out.println("=======欢迎登录========");
Scanner sc=new Scanner(System.in);
System.out.println("请输入用户名");
String name=sc.next();
System.out.println("请输入密码");
String pwd=sc.next();
yanzheng(name,pwd);
}
public static void yanzheng(String name,String pwd) throws IOException{
//1.实例化properties对象
Properties prop = new Properties();
//2.获得属性文件
FileInputStream fis = new FileInputStream("F:\\stu.properties");
//3.使用属性对象的load()方法获取内容
prop.load(fis);
//4.根据键获得值
String userName = prop.getProperty("userName");
String userpwd = prop.getProperty("pwd");
if(name.equals(userName)){
if(pwd.equals(userpwd)){
System.out.println("登录成功!");
}else{
System.out.println("密码错误!");
}
}else{
System.out.println("账号不存在!");
}
}
}