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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -