这是我在打开 txt 文件时使用的代码,但每次我想输入更多数据时它都会覆盖数据。
private Formatter X;
private File Y = new File("C:\\Users\\user\\workspace\\Property Charge Management System\\users.txt");
private Scanner Z;
public String[][] PCMSarray;
public boolean OpenFile() {
try{
if(Y.exists()==false){
X = new Formatter("users.txt");
}
return true;
}
catch(Exception e){
System.out.println("File has not yet been created.");
return false;
}
}
这是我用来写入文件的代码,但这有效。
public void WriteToFilecmd(){
Scanner input = new Scanner(System.in);
System.out.println("Please enter your First name");
String Fname = input.next();
System.out.println("Please enter your Last name");
String Lname = input.next();
System.out.println("Please enter your Password");
String Password = input.next();
System.out.println("Please enter your user ID");
String ID = input.next();
System.out.println("Please enter the first address line of your Property");
String addressln1 = input.next();
System.out.println("Please enter the second address line of your Property");
String addressln2 = input.next();
System.out.println("Please enter the third address line of your Property");
String addressln3 = input.next();
System.out.println("Please enter the properties estimated market value");
String EstimatedPropertyValue = input.next();
System.out.println("Please enter your tax owed");
String Taxowed = input.next();
input.close();
X.format("%1$20s %2$20s %3$20s %4$20s %5$20s %6$20s %7$20s %8$20s %9$20s \n",Fname,Lname,Password,ID,addressln1,addressln2,addressln3,EstimatedPropertyValue,Taxowed);
}