Solved

delete a line from a file

Posted on 2000-05-11
4
193 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 53
countX 22 67
Safari, Firefox, IE, Java, Plugin, Java Security error 13 38
strCopies  challenge 17 73
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now