Friday, 15 May 2015

java - BufferedReader readLine() method taking so much time -


I'm taking InputStream from one process and reading it through BufferedReader. While in the loop, however, the brow is only one line, it takes about 1 minute. I have been shown this before and after checking at the code below.

  string [] Send command = {"/ bin / bash", "/ users / apple / downloads / yowsup-e56f2d28f38c7961a2ccf7df588462f1c9588edf / sendmessage .sh"}; Processbilder processbilder = new process builder (); Processbuilder.directory (new file ("/ user / apple / download / yowsup-e56f2d28f38c7961a2ccf7df588462f1c9588edf")); Processbuilder.environment (). Put ("PYTHONPATH", "/ user / apple / download / yowsup-e56f2d28f38c7961a2ccf7df588462f1c9588edf"); ProcessBuilder.command (sendCommand); Process process = process builder. Start (); Process.waitFor (); InputStream stream = process.getInputStream (); BufferedReader br = new BufferedReader (new InputStreamReader (stream)); String floating = null; Println ("before"); Long start_time = System.currentTimeMillis (); While ((temp = br.readline ())! = Null {str = temp; } Long end_time = System.currentTimeMillis (); Long_talk = end_time-start_time; Println ("after"); System.out.println ("Time taken in the Loop:" + + TimeTata / 1000);  

The result was:

  after the time taken in the first loop: 67  

I want to improve it I'm taking 1 minute time too slow What are the possible options? Am I dependent on the process I am using? Please help me.

It's not reading, it's writing. BufferedReader can not be faster than the output of the output. If there is nothing to read, then this block is watching you the wrong end.

NB Your Loop is basically unusable, or the best is weird. You are reading each line, generates the process anytime and throws everyone, but the last line should definitely do something from every line?


No comments:

Post a Comment