1 Reply Latest reply: Nov 20, 2009 1:45 PM by 807580 RSS

    reg IOException

    807580
      In my program, I am performing addition of all numbers entered by user at command prompt, I am using Buffered reader to read the input, the program works fine for small data entered but when I past the large amount of data for example around 20 lines each having 4 digits seperated by space I get below exception:

      Exception in thread "main" java.io.IOException: Not enough storage is available to process this command
      at java.io.FileInputStream.available(Native Method)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:321)
      at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:411)
      at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:453)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:183)
      at java.io.InputStreamReader.read(InputStreamReader.java:167)
      at java.io.BufferedReader.fill(BufferedReader.java:136)
      at java.io.BufferedReader.readLine(BufferedReader.java:299)
      at java.io.BufferedReader.readLine(BufferedReader.java:362)
      at MainIO.main(Main.java:21)

      Interestingly, if instead of pasting all 20 rows at once if I past 10 rows twice I get output without any exception. Any thoughts whats going on??
                          BufferedReader bufferReader = new BufferedReader(new InputStreamReader(System.in));     
                             int Sum=0;
                                       //number of rows of input
                          int num = Integer.parseInt(bufferReader.readLine());     
                                    for(int k=0;k<num;k++){
                                              String[] row = bufferReader.readLine().split(" ");
                                              for(int l=0;l<row.length;l++){
                                                   Sum = Sum+Integer.parseInt(row[l]);
                                              }
                                         
                               System.out.println(Sum);
                               Sum=0;
                                                   
                          } 
      Edited by: RashmiPatel on Nov 20, 2009 11:39 AM