public static void setUser(String username, String password) { FileWriter fw; try { fw = new FileWriter("./web/user.txt", true); //就是这个构造方法的第二个参数,为true则是追加内容 BufferedWriter bw = new BufferedWriter(fw); bw.write(username); bw.write(" "); bw.write(password); bw.write("\n"); bw.close(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static void main(String[] args) { User.setUser("xxxx","xxxxxx"); }