Remove all the lines in a txt file that start with a string? (Java) -


right, have file format:


myfile.txt

name nickname;

jay epic1;

jay epic2;


now have string name = jay;. want remove lines start string name



so basically, want remove lines in txt file start string. possible? if so, can give me code? (i learn best looking @ code itself.)


thanks,

jay

here 1 possible implementation:

    string name = "jay ";      string source = "/path/to/original/file.txt";     string dest = "/path/to/new/modified/file.txt";      file fin = new file( source );     fileinputstream fis = new fileinputstream( fin );     bufferedreader in = new bufferedreader( new inputstreamreader( fis ) );      filewriter fstream = new filewriter( dest, true );     bufferedwriter out = new bufferedwriter( fstream );      string aline = null;     while( ( aline = in.readline() ) != null ) {         // check each line string, , write if doesn't have it:         if( !aline.startswith(name) ) {             out.write( aline );             out.newline();         }     }      in.close();     out.close(); 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -