{"id":3731,"date":"2014-03-29T09:21:09","date_gmt":"2014-03-29T09:21:09","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/problem-about-bufferedreader-collection-of-common-programming-errors\/"},"modified":"2014-03-29T09:21:09","modified_gmt":"2014-03-29T09:21:09","slug":"problem-about-bufferedreader-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/problem-about-bufferedreader-collection-of-common-programming-errors\/","title":{"rendered":"problem about bufferedreader-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e4bcb17967dd5b94a673cc2e8e63c295?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRajdeep Siddhapura<br \/>\njava java-util-scanner stdin bufferedreader inputstreamreader<br \/>\nIn the given code,Input: 1 7Output: 1Output should be 7. What am I missing??import java.io.*; import java.util.*;class compiler {public static void main(String args[] ) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int testcases = Integer.parseInt(br.readLine());\/\/ System.out.println(&#8220;If this statement is added it works as expected!&#8221;)int n=Integer.parseInt(br.readLine());System.out.println(n);} }*I also tried using scanner<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d5f91983a9d9cfb69981b6108a63b412?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nskaffman<br \/>\njava inputstream bufferedreader apache-commons-vfs<br \/>\nI am trying to read one line at a time using bufferedReader like followingBufferedReader.readLine() and I am getting the following stack trace.java.io.EOFException: Unexpected end of ZLIB input stream at java.util.zip.ZipFile$1.fill(ZipFile.java:240) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read1(BufferedInputStream.java:258) at java.io.BufferedInputStream.read(Buffered<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ba8224e333fcbdd24325bcd87de1e962?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nD.Singh<br \/>\njava input io bufferedreader<br \/>\nWhen I run the following code and type 50 when prompted for input:private static int nPeople;public static void main(String[] args) {nPeople = 0;System.out.println(&#8220;Please enter the amount of people that will go onto the platform : &#8220;);BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));try {nPeople = keyboard.read();} catch (IOException e) {e.printStackTrace();}System.out.println(&#8221; The number of people entered &#8211;&gt; &#8221; + nPeople); }}I get the following output:Please en<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/PZnlu.png?s=32&amp;g=1\" \/><br \/>\nDukeling<br \/>\njava encoding replace bufferedreader<br \/>\nI got unexpected behavior while performing several operation on String.I found:String expectedString=&#8221;ami\\303\\261o&#8221;; its output is like: ami\u00c3\u00b1oString str=&#8221;ami\\\\303\\\\261o&#8221;; its output is like: ami\\303\\261oorIf we read this string from file using BufferedReader(readline) its value is: ami\\303\\261oHow would I get a string of ami\u00c3\u00b1o from str=&#8221;ami\\\\303\\\\261o&#8221; or from reading the file (ami\\303\\261o) using the BufferedReader?Any kind of replace, conversion, regexp or anything is acceptable.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/119abb74a9cbc5bcda419da1f486656b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1611395<br \/>\njava sockets bufferedreader serversocket printwriter<br \/>\nI&#8217;m trying to read data from socket using threading run method:@Override public void run() {while(true){try{String o = &#8220;&#8221;;socketServer = new ServerSocket(port);System.out.println(&#8220;Waiting for connection on port &#8220;+port+&#8221;.&#8221;);Socket socket = new Socket();socket = socketServer.accept();System.out.println(&#8220;Connection got.&#8221;);BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));int c;while(( c = input.read()) != -1)o += (char)c;PrintWriter output = new PrintWriter(s<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c453e93b01bc12365b1aa85c6a262df8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1971455<br \/>\njava process bufferedreader<br \/>\nIn the while loop below I want to read only the newest line from Process p&#8217;s output, ignoring anything else that entered the buffer while the loop was sleeping. How do I do that?String s; Runtime r = Runtime.getRuntime(); Process p = r.exec(&#8220;SomeContinuousProgram&#8221;); myInput = new BufferedReader(new InputStreamReader(p.getInputStream()));while (true){if ((s = myInput.readLine()) != null) {System.out.println(s);} Thread.sleep(sleep); }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/96d8f095a4031364b245a374f4f32c7a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTravis Nelson<br \/>\njava windows parsing windows-xp bufferedreader<br \/>\nI have some code that does a Runtime exec and parses the results. On linux and Windows7, the code works fine for parsing the system commands, but on Win XP I am getting a blank line (&#8220;&#8221;) between each line that has content. Any ideas what might be happening here? Process output = Runtime.getRuntime().exec(command); BufferedReader br = new BufferedReader(new InputStreamReader(output.getInputStream())); while ((line = br.readLine()) != null) {\/\/do stuff }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e4661848431df0fdc21d469301668c3f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\n???<br \/>\njava ping bufferedreader runtime.exec<br \/>\nI managed to modify a program to ping peer computer and gets the ping counts. How can I parse out the time = ?ms from the ping count results, in real-time?Code:public static void main(String[] args) {String ip = &#8220;192.168.1.1 -n 10&#8221;;String pingResult = &#8220;&#8221;;String pingCmd = &#8220;ping &#8221; + ip;try{Runtime r = Runtime.getRuntime();Process p = r.exec(pingCmd);BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));String inputLine;while ((inputLine = in.readLine()) != null) {System<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/57b2d849509d2058cee4344af8785de9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSecator<br \/>\njava bufferedreader<br \/>\nI am Getting a run time Exception while using this codeRuntime rt = Runtime.getRuntime(); System.out.println(&#8220;Executing &#8221; + &#8220;uname -a&#8221;); Process x = rt.exec(&#8220;ping IP Address of system&#8221;); BufferedReader stdInput =new BufferedReader(new InputStreamReader(x.getInputStream())); BufferedReader stdError =new BufferedReader(new InputStreamReader(x.getErrorStream())); String line = null; while ((line = stdInput.readLine()) != null) {System.out.println(line); } x.waitFor();<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f8bd1c472fe5832e125fd4008578608a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njWeaver<br \/>\nconsole java-util-scanner bufferedreader java-6 java-5<br \/>\nI was reading about Console class, and in the very first line, it was written New to Java 6 and when we are running Java SE 6 from command line, then we are typically using console class objectSo, which means we are implicitly using console class through the command line ??Then, start searching about the console class, i found Input from console class in java and Console link. I conclude some pointsConsole class are only usable outside the IDE using System.console().readLine();Console class read<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d49ca28d6b846e64951858f6848432e4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nWATTO Studios<br \/>\njava bufferedreader<br \/>\nThe below code is not getting executed completely after this line &#8221; bufferedReader.readLine(); &#8220;. The Program works fine when i execute the system command with out mentioning IPAddress of the remote PC.class Test { public static void main(String arg[]) { Process p; Runtime runTime; String process = null; try { runTime = Runtime.getRuntime(); p = runTime.exec(&#8220;sc \\\\xx.xx.xx.xx query gpsvc&#8221;); \/\/ For Windows InputStream inputStream = p.getInputStream(); I<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d49ca28d6b846e64951858f6848432e4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nWATTO Studios<br \/>\njava file bufferedreader ioexception filenotfoundexception<br \/>\nI&#8217;m very confused on getting basic file reading to work with Java. Lots of mixed signals.I&#8217;ve tried it a couple different ways and I consistently get a not found exception each time. I&#8217;ve checked with a file object set to the current path to print the current directory and I am indeed in the directory the file I&#8217;m trying to open is in. The permissions are set so everyone can read. I&#8217;m not sure what is going on:BufferedReader infixLines = new BufferedReader ( new FileReader ( &#8220;input.infix&#8221; ))<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/06cb464e94c3b07c8fbfab4d9a1159ee?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nepsac<br \/>\njava bufferedreader<br \/>\nI have the following code in java that calls the date command in the command prompt:\/\/ prepare command prompt runtime and process Runtime runtime = null; Process process = null;\/\/ prepare output stream OutputStream outputStream = null;try {runtime = Runtime.getRuntime(); \/\/ instantiate runtime objectprocess = runtime.exec(&#8220;date&#8221;); \/\/ get the current date in command prompt\/\/ read the output of executing date commandoutputStream = process.getOutputStream();\/\/ output the date responseSystem.out.pri<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/u0yRm.jpg?s=32&amp;g=1\" \/><br \/>\ndoonot<br \/>\njava process pdf-generation bufferedreader wkhtmltopdf<br \/>\nI am running wkhtmltopdf from Java. I create a process but this one seems to be hanging, as it repeats again and again the the console, also in the Task Manager.This is how I run wkhtmltopdf:String command = applicationLocation + &#8220;wkhtmltopdf.exe -O Landscape &#8221; + reqURL + &#8220;?&#8221; + reqQuery + &#8221; c:\/PDF\/&#8221; + folderName + &#8220;\/&#8221; + id + &#8220;\/&#8221; + folderName + &#8220;.pdf&#8221;; Process p = Runtime.getRuntime().exec(command);How can I &#8220;destroy&#8221; the process, after the job has been done?This did not work for me, the process<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/571036e2f54b8f3e73473ce015a8da15?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nZippy<br \/>\njava file-io bufferedreader readline<br \/>\nIf I have something like this in my code:String line = r.readLine(); \/\/Where r is a bufferedReaderHow can I avoid a crash if the next line is the end of the file? (i.e. null)I need to read the next line because there may be something there that I need to deal with but if there isn&#8217;t the code just crashes.If there is something there then all is OK, but I can&#8217;t be guaranteed that there will be something there.So if I do something like: (pseudo code):if (r.readLine is null) \/\/End codeelse {check l<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/481baa815383ed3970e726842195f73f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nhqt<br \/>\njava bufferedreader filechannel<br \/>\nFileChannel will faster than BufferedReader, BufferedReader will more faster than Reader because FileChannel and BufferedReader has cut off some itermediate steps to receive data. My question is : the advantage is obvious, but I don&#8217;t see any source on web say about its disadvantage. (of FileChannel to BufferedReader, BufferedReader to Reader). What a problem when we cut off intermediate steps between.So, who can teach me,please.@:And, the same question for Output, too. Please tell me what disad<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/81a5455e5a76baaf7e81408e56151539?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKeeb13r<br \/>\njava android exception-handling try-catch bufferedreader<br \/>\nI&#8217;m writing an Android application that is connecting to a website and retrieving search results in the form of JSON. This function is happening in an AsyncTask, which is set up as a separate stream from the UI. I need to handle the case where the connection is interrupted\/non-existent\/too latent. I need to handle this case in order to display an AlertDialog to the user letting them know the connection is bad. I&#8217;ve seen posts suggest setting a timeout parameter for URLConnection, but I&#8217;m not usi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f62561cb4ac4b1b719ad7e5bedf18675?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ncheese5505<br \/>\njava bufferedreader bufferedwriter<br \/>\nI am making a program for someone that read\/writes to a file. I created it, and tested it, but it crashes when I tell it the name. Code:import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.Scanner;public class Main { public static void main(String[] args) throws Exception {Scanner scanner = new Scanner(System.in);print(&#8220;Enter a name for the bell:<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/52b138372132459059b0fc17a66bc07d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJLaw<br \/>\nandroid bufferedreader fileinputstream<br \/>\nI&#8217;ve solved my own issue but I don&#8217;t know why my first attempt didn&#8217;t work and I was hoping someone could tell me why. I was also hoping if someone could tell me if my final solution is a &#8220;good&#8221; one or not (by this I mean, is it efficient)?This was my first attempt at reading an input file I had previously created:private byte[] mInputData;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.second_view);Intent myIntent = getIntent();mFilena<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/49a75a851b25eb03b64862f20292872c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nZak<br \/>\nandroid json bufferedreader<br \/>\ni&#8217;ve got this code which work fine on android &lt;4:try{URL url = new URL(&#8220;http:\/\/www.mysite.com\/data.php&#8221;);BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));while((testo=in.readLine()) != null){testo2+=testo;}in.close();JSONObject jObject = new JSONObject(testo2);button.setText(jObject.getString(&#8220;n&#8221;));textView1a.setText(&#8221; &#8220;+jObject.getString(&#8220;so&#8221;));textView1b.setText(jObject.getString(&#8220;tc&#8221;)+&#8221; &#8220;);}catch(MalformedURLException e){System.out.println(&#8220;1&#8221;);}catch(IOExcep<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/53ee9941b3fefef67175daf212e62d41?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPeter Lawrey<br \/>\njava bufferedreader<br \/>\nI have some problems reading file in java: my file is for example:3,4 2 6 4 1 7 3 8 9where first line 3 and 4 are the lenght of array A and B and then the element of each array. I made thisimport java.io.*; import java.util.Arrays;public class Progetto {public static void main(String args[]){ \/\/ Open the file that is the first \/\/ command line parameterFileInputStream fstream = new FileInputStream(&#8220;prova.txt&#8221;);BufferedReader br = new BufferedReader(new InputStreamReader(fstream));String strLine<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f3b0e92e8a603e598eb99d3ced9c6d14?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNS114<br \/>\njava android bufferedreader urlconnection<br \/>\nI am trying to read the content of a URL. The initialization of the BufferedReader keeps causing the crash.I&#8217;ve tried looking up peoples&#8217; solutions, but no matter what I do, I get this error.Here is my code:try {String sUrl = &#8220;http:\/\/www.google.com&#8221;;System.out.println(&#8220;About to create URL.&#8221;);URL url = new URL(sUrl);System.out.println(&#8220;Created URL&#8221;);System.out.println(&#8220;About to create URLConnection&#8221;);URLConnection urlc = url.openConnection();System.out.println(&#8220;Created URLConnection&#8221;);System.out.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/888b31af96427e8bd603631fa2af32f5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser unknown<br \/>\njava bufferedreader numberformatexception<br \/>\nI have been trying to figure this out for couple of hours now and I hope one of you can help me. I have an file (actually two but thats not important) that have some rows and columns with numbers and blank spaces between. And I&#8217;m trying to read those with BufferedReader. And that works great. I can print out the strings &amp; chars however I want. But when I try to parse those strings and chars I get the following error: Exception in thread &#8220;main&#8221; java.lang.NumberFormatException: For input strin<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/632732029bf05854c17d0dea6c82dcb4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntrashgod<br \/>\njava file-io jtable bufferedreader stringtokenizer<br \/>\nI am trying to replace character ( and ) from a file with a comma so that I can use the code below for entering data in to a JTable from a csv file. I have tried to do this by reading the file with a StringTokenizer and i&#8217;ve tried manipulating the way that I implement it and I can&#8217;t get it to run with NullPointerException. I understand that it can&#8217;t find an object that it is pointing to but i can&#8217;t see where my problem is. Any pointers would be great as I&#8217;ve been stuck on this for hours. Is the<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rajdeep Siddhapura java java-util-scanner stdin bufferedreader inputstreamreader In the given code,Input: 1 7Output: 1Output should be 7. What am I missing??import java.io.*; import java.util.*;class compiler {public static void main(String args[] ) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int testcases = Integer.parseInt(br.readLine());\/\/ System.out.println(&#8220;If this statement is added it works as expected!&#8221;)int n=Integer.parseInt(br.readLine());System.out.println(n);} }*I also tried [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3731","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3731"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3731\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}