我的问题是我无法弄清楚如何使用文件阅读器读取客户姓名。
我正在制作预订系统,我需要知道客户已经存在。这就是为什么我必须阅读我的 Customers.txt 文件,以便检查某人是否已经是客户。如果他不是,我将使用 File writer 制作一个新的(我已经有了代码)。
这个预约系统的意思是和理发师预约。我必须将预订放在另一个名为 Reservations.txt 的 txt 文件中,在该文件中,您可以看到每个预订时间以及谁进行了预订。
谢谢您的帮助!
这是我已经拥有的代码:(一些评论是荷兰语,但我会翻译它们)
package nielbutaye;
import java.io.*;
import java.util.UUID;
/**
* @author Niel
*
*/
public class Klant {
//declaration that represents the text
public static String S;
public static String NEWLINE = System.getProperty("line.separator");
/**
* constructor
*/
public Klant(){}
/**
* @return
* By giving the name of the customer you will get all the data from the customer
*/
public double getCustomer() {
return 0 ;
}
/**
* Make a new customer
*/
public void setNew customer(){
// make a newSimpleInOutDialog
SimpleInOutDialog input = new SimpleInOutDialog("A new customer");
//input
S = "Name customer: " + input.readString("Give in your name:");
WriteToFile();
S = "Adress: " + input.readString("Give your adress");
WriteToFile();
S = "Telephonenummber: " + input.readString("Give your telephonenumber");
WriteToFile();
//making a customerID
UUID idCustomer = UUID.randomUUID();
S = "CustomerID: " + customerID.toString();
WriteToFile();
}
public void WriteToFile(){
try{
FileWriter writer = new FileWriter("L:\\Documents/Informatica/6de jaar/GIP/Customer.txt", true);
BufferedWriter out = new BufferedWriter(writer);
//Wrting away your data
out.write(S + NEWLINE);
//Closing the writer
out.close();
}catch (Exception e){//Catch when there are errors
System.err.println("Error: " + e.getMessage());
}
}
}