java - Remove a certain character from a .txt file -


if type

java deletex e < input.txt > output.txt 

in terminal, code supposed remove character (in case e) input.txt file , save same text new file output.txt es should removed.

ex: if text in input.txt follows:

hello! name john doe.

the output.txt file should be:

hllo! nam john do.

but don't spaces in output.txt. get:

hllo!mynamisjohndo.

code:

public class deletex{ public static void main(string []args){  string x = args[0]; // character want removed text char x = x.charat(0); // transform character string char      while(! stdin.isempty()){         string line = stdin.readstring(); // .txt file          for( int = 0; < line.length(); i++){               if( line.charat(i) != x ){                 system.out.print(line.charat(i));              } // if                      } //      } // while     } // main } // class 

i think better way use replace method on string.

like:

line = line.replace(x, ""); 

and print out.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -