Solved

delete a line from a file

Posted on 2000-05-11
4
219 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 63
Tomcat: Unable to run tomcat service. 2 23
maven disable workspace resolution 1 19
ejb mdb examples 1 6
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 video teaches viewers about errors in exception handling.

809 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