数据库系统作业要求先自己建一个txt文件,每行12位数字,前六位是用户名,后六位是相应的密码,要用java创建一个用户登陆界面验证密码是否正确。一点不会java,求完整程序包

解决方案 »

  1.   

    String account = "111111";
    String password = "111111";
    Map<String, String> map = new HashMap<String , String>();
    String path = "D:\\test.txt";
    File file = new File(path);
    BufferedReader bReader = new BufferedReader(new FileReader(file));
    String string =  "";
    String pc [] = null;
    String key = "";
    String value = "";
    while ((string = bReader.readLine()) != null) {
    pc = string.split(",");
    key = pc[0];
    value = pc[1];
    map.put(key, value);
    }
    Set<String> keySet = map.keySet();
    for (String string2 : keySet) {
    System.out.println(string2);//账号
    System.out.println(map.get(string2));//密码
    if (account .equals(string2) && password.equals(map.get(string2))) {
    System.out.println("账号密码正确");
    break;
    }else {
    System.out.println("账号密码错误");
    }
    }
    bReader.close();
    //txt文本,密码和账号之间用英文逗号分隔
      

  2.   

    String account = "111111";
    String password = "111111";
    Map<String, String> map = new HashMap<String , String>();
    String path = "D:\\test.txt";
    File file = new File(path);
    BufferedReader bReader = new BufferedReader(new FileReader(file));
    String string =  "";
    String pc [] = null;
    String key = "";
    String value = "";
    @SuppressWarnings("unused")
    boolean result = false;
    while ((string = bReader.readLine()) != null) {
    pc = string.split(",");
    key = pc[0];
    value = pc[1];
    map.put(key, value);
    }
    Set<String> keySet = map.keySet();
    for (String string2 : keySet) {
    System.out.println(string2);//账号
    System.out.println(map.get(string2));//密码
    if (account .equals(string2) && password.equals(map.get(string2))) {
    result = true;
    break;
    }
    }
    if (result = false) {
    System.out.println("密码错误");
    }else {
    System.out.println("账号密码正确");
    }
    bReader.close();
    刚那个有点问题,改了一下