0

I am making a Flight reservation system for my course project and I am having problems using StringBuilder which my teacher asked me to use in my code.

I wrote this method to delete a customer's data from a text file which I am using for storing the customer's details and the ticket number I assigned to them now this method takes the ticket number and searches in the text file and delete that entry (line of text file). The text file is formatted in this way

(name + "\t" + socialNum + "\t" + cellNum + "\t" + tickNum + "\n")

The problem is that when I check the text file manually I see that The file was correctly formatted before but after running this method it is not.( The last escape sequence i.e "\n" is not being printed to the file).

public static void deleteData(String b) throws FileNotFoundException {
    Scanner input = new Scanner(Basic.file); // Text file used as Database
    while (input.hasNext()) {
        String a = input.nextLine();
        a = a.trim();
        a = a.toUpperCase(Locale.ROOT);
        if (a.contains(b)) {
            continue;
        }
        Basic.c.append(a).append("\n"); // c is StringBuilderObj

    }
    if ((Basic.c.toString()).equals("")) {
        System.out.println("Invalid Ticket Number.");
    } else {
        try (PrintWriter out = new PrintWriter(Basic.file)) {
            String result = Basic.c.toString();
            out.println(result);

        }
    }

0 Answers0