3 Replies Latest reply on Dec 24, 2003 9:52 AM by 807582


      hi all, how do i receive and read from the input stream which will return me a string?

      thanks in advance

      p.s. a working sample would be nice
      int k = conn.getContentLength();  //though i dont have  any idea, 
                                                                            //this is roughly what i got from the net
      byte[] array = new byte[k];
      InputStream is = conn.getInputStream();
      int n = is.read(array);
      String content = new String(array);
        • 1. Re: getInputStream
          To read from the default input stream use
          public String readAString(int len)//len is how long you want to read;
            InputStream is=System.in;//System.in is the "standard input stream and is always defined;
            byte[] array=new byte[len];
            is.read(array, 0, len);//read to this array for len bytes;
            String result=new String(array);
          Use any InputStream in the same way, for example to read from file
          InputStream is=URL.openStream();
          • 2. Re: getInputStream
            hi, tried it. but not satisfied with the result and thinking of using the buffered reader or writer but do not know how. can u help me out here? ^_^
            InputStream is =null; 
            BufferedWriter out = 
            new BufferedWriter( new OutputStreamWriter( conn.getInputStream() ) );
            byte[] array=new byte[1048];
            //read to this array for len bytes;  
            is.read(array, 0, 1048);  
            String result=new String(array);
            many thanks

            p.s. comments are welcomed
            • 3. Re: getInputStream
              got the solution. i had to read line by line. does anyone has any idea 'bout the xml reader?