Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:37:47+00:00 2026-05-31T02:37:47+00:00

What I’m trying to do is to delete a reservation I made The reservation

  • 0

What I’m trying to do is to delete a reservation I made
The reservation look like this in the txt file

08:00
Niel Butaye
1

The code That I have to delete the reservation is:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.File;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;

public class ReservatieVerwijderen {
    static String naamklant="";
    public ReservatieVerwijderen() {}

  public void removeLineFromFile(String file, String lineToRemove) {

    try {

      File inFile = new File(file);

      if (!inFile.isFile()) {
        System.out.println("Parameter is not an existing file");
        return;
      }

      //Maak een nieuw bestand dat later het originele bestand wordt
      File tempFile = new File(inFile.getAbsolutePath() + ".tmp");

      BufferedReader br = new BufferedReader(new FileReader(file));
      PrintWriter pw = new PrintWriter(new FileWriter(tempFile));

      String line = null;

      //Lees het originele bestand en schrijf naar het tijdelijke bestand 
      //Als de lijn == de lijn die we zoeken schrijven we dit niet over
      while ((line = br.readLine()) != null) {

        if (!line.trim().equals(lineToRemove)) {

          pw.println(line);
          pw.flush();
        }
      }
      pw.close();
      br.close();

      //Verwijder het originele bestand
      if (!inFile.delete()) {
        System.out.println("Could not delete file");
        return;
      } 

      //Hernoem het tijdelijke bestand naar het originele
      if (!tempFile.renameTo(inFile))
        System.out.println("Could not rename file");

    }
    catch (FileNotFoundException ex) {
      ex.printStackTrace();
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
  }

  public static void main(String[] args) {
    ReservatieVerwijderen util = new ReservatieVerwijderen();
    SimpleInOutDialog  input = new SimpleInOutDialog("Reserveringen");
    naamklant = input.readString("Geef de volledige naam in");
    util.removeLineFromFile("L:\\Documents/Informatica/6de jaar/GIP/Reserveringen.txt", naamklant);
  }
}

It only deletes the name of the reservation maker , I need to delete the hour(08:00) and kind of reservation(1) too. Any help ?

public class SimpleInOutDialog {

    private String titel;

    /**
     * Constructor van een SimpleInOutDialog.
     *
     * @param titel een String met de titel van het venstertje.
     */
    public SimpleInOutDialog(String titel) {
        this.titel = titel;
    }
    /**
     * Tonen van een tekst in een dialoogvenstertje. 
     * @param message een String met een te tonen berichtje.
     * @param output een String met de te tonen tekst.
     */
    /**
    *  
    * @param 
    */


    public void showString(String message, String output) {
        JOptionPane.showMessageDialog(
            null,
            message + "\n\n" + output + "\n\n",
            titel,
            JOptionPane.PLAIN_MESSAGE);

    }

    /**
    * Tonen van een geheel getal in een dialoogvenstertje.  
    * @param message een String met een te tonen berichtje.
    * @param een int met het te tonen getal.
    */
    public void showInteger(String message, int getal) {
        JOptionPane.showMessageDialog(
            null,
            message + "\n\n" + Integer.toString(getal) + "\n\n",
            titel,
            JOptionPane.PLAIN_MESSAGE);

    }

    /**
    * Tonen van een geheel getal in een dialoogvenstertje.
    * @param message een String met een te tonen berichtje.  
    * @param een double met het te tonen getal.
    */
    public void showDouble(String message, double getal) {
        JOptionPane.showMessageDialog(
            null,
            message + "\n\n" + Double.toString(getal) + "\n\n",
            titel,
            JOptionPane.PLAIN_MESSAGE);
    }

    /**
     * Inlezen van een String.
     * @param message een String met de tekst die in het dialoogvenster
     * moet getoond worden.
     * @return de ingelezen String.  Indien het venster zonder
     * invoer wordt afgesloten is de String null.
     */
    public String readString(String message) {
        Object[] possibilities = null;
        String s = null;
        s =
            (String) JOptionPane.showInputDialog(
                null,
                message,
                this.titel,
                JOptionPane.PLAIN_MESSAGE,
                null,
                possibilities,
                "");

        if ((s == null) || (s.length() == 0)) {
            s = null;
        }
        return s;
    }

    /**
     * Inlezen van een geheel getal.
     * @param message een String met de tekst die in het dialoogvenster
     * moet getoond worden.
     * @return het ingelezen geheel getal (een int).  Indien het venster zonder
     * correcte invoer wordt afgesloten is het getal 0 (nul).
     */
    public int readInteger(String message) {
        boolean isAnInteger = false;
        String tekst = null;
        int gelezen = 0;
        while (!isAnInteger) {
            tekst = readString(message);
            if (tekst != null) {
                try {
                    gelezen = Integer.parseInt(tekst);
                    isAnInteger = true;
                } catch (NumberFormatException nfe) {
                    isAnInteger = false;
                }
            } else {
                isAnInteger = true;
                gelezen = 0;
            }
        }
        return gelezen;
    }

    /**
     * Inlezen van een kommagetal.
     * @param message een String met de tekst die in het dialoogvenster
     * moet getoond worden.
     * @return het ingelezen getal (een double).  Indien het venster zonder
     * correcte invoer wordt afgesloten is het getal 0.0 (nul).
     */
    public double readDouble(String message) {
        boolean isADouble = false;
        String tekst = null;
        double gelezen = 0.0;
        while (!isADouble) {
            tekst = readString(message);
            if (tekst != null) {
                try {
                    gelezen = Double.parseDouble(tekst);
                    isADouble = true;
                } catch (NumberFormatException nfe) {
                    isADouble = false;
                }
            } else {
                isADouble = true;
                gelezen = 0.0;
            }
        }
        return gelezen;
    }

    /**
     * Wanneer je in je programma geen uitvoer meer nodig hebt 
     * MOET je deze bewerking op het SimpleInOutDialog-object uitvoeren.
     * Het programma wordt dan beëindigd.
     */
    public void stop() {
        System.exit(0);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:37:47+00:00Added an answer on May 31, 2026 at 2:37 am

    You get much cleaner code if you think in complete reservations instead of individual lines:

    void deleteReservations(String reservationName, BufferedReader input,
          PrintWriter output) throws IOException {
        String date;
        while ((date = input.readLine()) != null) {
          String name = input.readLine();
          String tickets = input.readLine();
    
          // You can check any part of a reservation here
          // to figure out wether to keep or delete it.
          if (!name.equals(reservationName)) {
            output.println(date);
            output.println(name);
            output.println(tickets);
          }
        }
      }
    

    This will obviously fail on files that are not following the 3-line-block format, but then again, the file is broken anyway.

    Sample input based on Sergey Brenner’s answer:

    08:00
    Niel Butaye
    1
    09:00
    dean koontz
    2
    10:00
    stephen king
    3
    

    given the name dean koontz outputs:

    08:00
    Niel Butaye
    1
    10:00
    stephen king
    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.