Thread: Delete
View Single Post
  #2 (permalink)  
Old 02-28-2008, 03:03 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,119
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by nogono View Post
In a file,line ends with Dot(.)
I want to delete this particular line from file and update the file..
I may misunderstood on what you're trying to do, but since you're not giving any scenarios, I'm assuming that you want to remove any lines within a file that ends with Dot (.)

The way to do this is basically reading through the file line by line, then each time you are about to go to the next line, then check if there's a dot at the end of the string...

Code:
BufferedReader br = new BufferedReader(new FileReader("filename.txt"));
String line = br.nextLine(); // this is first line, check it
if (line.charAt(line.length()) == '.') {
   // remove the line by replacing the line string by "" string, then append it
}
and so forth...
code hasn't been tested, but for your reference... take a look at Java Library for String:

String (Java 2 Platform SE 5.0)

Here's further tutorial on reading from a file:
Tutorial: How to read from ASCII files

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote