Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default Converting InputStream to OutputStream

    Code sample below converts inputstream to outputstream.
    Java Code:
    import java.io.*; 
    public class InputToOutputStream
    {
       public static void main( String args[] )
    throws IOException
         {
         InputStream in = new FileInputStream
    ( "InputToOutputStream.java" );
         OutputStream out = System.out;
         int nextChar;
         while ( ( nextChar = in.read() ) != -1  )
         out.write(  Character.toUpperCase( 
    (char) nextChar ) );
         out.write( '\n' );
         out.flush();
         }
    }

  2. #2
    afsina is offline Member
    Join Date
    Jan 2008
    Posts
    24
    Rep Power
    0

    Default

    Some corrections:

    this class does not convert an inputstream to outputstream. what it does is writing a file's contents to the console as character by character and adding a new line after each character . Also this method works, but you should close streams in finally blocks, and you don't need to flush the output stream after each write operation..

Similar Threads

  1. Converting URL to URI
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:15 AM
  2. Replies: 0
    Last Post: 11-27-2007, 10:23 AM
  3. Reading bytes from InputStream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-25-2007, 07:51 PM
  4. Un expected behaviour when reading from inputstream
    By adoorsarath in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2007, 05:02 PM
  5. HashMap to share OutputStream
    By gabriel in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 05:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •