我正在尝试如何使用文件处理来创建注册页面,该页面将生成一个文本文件:“ database.txt”。第一次填写要求。结果很好,但是当您第二次再次注册时,它只是附加了它,并没有按照我喜欢的方式设置它,我喜欢这样。
我已经在各种网站,链接中搜索了类似的问题,但是我似乎无法理解。
Scanner input = new Scanner(System.in);
String filepath = "C:\\Users\\Sparda\\Desktop\\Database.txt";
try {
FileOutputStream fos = new FileOutputStream(filepath, true);
System.out.println("Enter Username");
String user = input.nextLine();
System.out.println("Enter Password");
String pass = input.nextLine();
String data = user + (",") + pass;
fos.write(data.getBytes());
System.out.println("Registered Successfully!");
}
catch (FileNotFoundException ex) {
System.out.println("FileNotFoundException: " + ex.toString());
}
catch (IOException ioe) {
System.out.println("IOException: " + ioe.toString());
}
catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
}
}
实际输出为:
我的预期输出应该是:
答案 0 :(得分:1)
您可以改写 - match:
- uri:
prefix: /service-a
rewrite:
uri: /