?
Solved

delete a line from a file

Posted on 2000-05-11
4
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 20 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 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