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 9091619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:39:12+00:00 2026-06-16T22:39:12+00:00

Possible Duplicate: Java – Find a line in a file and remove I have

  • 0

Possible Duplicate:
Java – Find a line in a file and remove

I have a code that Get id number and search for its records, if exist, display it.

I want if found, delete it record.
One solution for delete a line( a user record) is create another file and copy all lines without found record.
can anyone tell me another solution? (Simple solution)

my BookRecords.txt file is this:

Name        Date        Number

one   2002   22
two   2003   33
three   2004   44
four   2005   55

my Code to find :

String bookid=jTextField2.getText();
File f=new File("C:\\BookRecords.txt");
try{
    FileReader Bfr=new FileReader(f);
    BufferedReader Bbr=new BufferedReader(Bfr);
    String bs;
    while( (bs=Bbr.readLine()) != null ){
    String[] Ust=bs.split("   ");
    String Bname=Ust[0];
    String Bdate=Ust[1];
    String id = Ust[2];
    if (id.equals(bookid.trim()) 
    jLabel1.setText("Book Found,    "+ Bname + "    " + Bdate);
    break;
        }
      }
    }
catch (IOException ex) {
    ex.printStackTrace();
} 

please help to delete a Line(a Record)

Thanks.

  • 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-06-16T22:39:13+00:00Added an answer on June 16, 2026 at 10:39 pm

    Working on a single text file is – uhm – a bit strange. But I would recommend, that you create a new text file (output):

    PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
    

    Only write the lines that don’t match the book’s ID.

    while (...) {
        ...
        if (!id.equals(bookid.trim())) {
            out.println(bs);
        }
    }
    out.close();
    

    Later you can rename the file, if you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java garbage collection I know that we have to free object in
Possible Duplicate: Java - Using Jena APi - Get data from RDF file I'm
Possible Duplicate: Java: how to clone ArrayList but also clone its items? I have
Possible Duplicate: Java code to execute a .sh file I write the code in
Possible Duplicate: Java Hashmap: How to get key from value? I know that a
Possible Duplicate: Java API to parse XSD schema file I have a requirement to
Possible Duplicate: Java char array to int I have the following code, where stackCells
Possible Duplicate: Java Library: Command Line Option Parser I have to build a Java
Possible Duplicate: Java: recommended solution for deep cloning/copying an instance I have an object
Possible Duplicate: Java: how to check that a string is parsable to a double?

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.