Solved

delete a line from a file

Posted on 2000-05-11
4
213 Views
Last Modified: 2010-04-01
I have a file which is something like this:

aaaa:zzz
bb:yy
ccccccc:xx

Now I search through the file for a particular string, say "bb". Once I get the match in the file I want to delete that line "bb:yy". How do I do that?

This file will be accessed by scripts many times, could be at the same time.
I need to take care of that too?

-Sunita
0
Comment
Question by:ssunitas
  • 2
4 Comments
 

Expert Comment

by:ashcrowd
ID: 2801406
Use an input and output buffer as you read each line in if it is ok append it to the output buffer otherwise read the next line.
0
 

Author Comment

by:ssunitas
ID: 2801780
How can I read the whole file in one shot into another file or into an array?
0
 

Accepted Solution

by:
java_world earned 10 total points
ID: 2804500
Hi Sunita,
What you do?
Search for your String and at the same time,
store the lines which doesn't have your String
and then at last i.e. at the end of line,
copy that Long String into your file Ok by recreating the same file.
Your doubt is that how can i have next lines in the String. It's easy yaar, just you Concat with
"\n" wherever you want to have a next line.
Satisfied.
Try it out, I am there
bye
-praveen from U.S.
0
 

Expert Comment

by:ashcrowd
ID: 2804543
I don't think you would want to read the whole file at once just a line at a time.  The fileBufferReader will do that for you.


try
  {
        aFile = new bufferedReader(new FileReader(fileName));
      while (aFile.readLine() != null)
      {
          //do your checks here if ok add line to output
      }

  }
catch (IOException exception)
      {
                        //io error here
                 }

            
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 40
difference of if loops 23 49
null output 3 25
jboss wildfly 10.1 10 85
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question