注册

来源:互联网 发布:java三大特征 编辑:程序博客网 时间:2024/05/16 00:57
package test;


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;


public class Reg {


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();

reg(name,pwd);


}


public static void reg(String name, String pwd){
// 1.创建properties对象
Properties prop = new Properties();


// 2.指定输出文件
FileOutputStream fos = null;

try {
fos = new FileOutputStream("F:\\stu.properties");


// 3.设置要输出的属性
prop.setProperty("userName", name);
prop.setProperty("pwd", pwd);


// 4.保存文件
prop.store(fos, "这是一个注释");

System.out.println("注册成功!");
} catch (IOException e) {
// e.printStackTrace();
System.out.println("注册失败!");
} finally {
if(fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}



}


}
0 0