Java programming language provides streams to read data from a file, a socket and from other sources e.g. byte array, but developers often find themselves puzzled with several issues e.g. how to open connection to read data, how to close connection after reading or writing into file, how to handle
IOException e.g.
FileNotFoundException,
EOFFileException etc. They are not confident enough to say that this code will work perfectly. Well, not everyone expect you to make that comment, but having some basics covered always helps. For example In Java, we read data from file or socket using
InputStream and write data using
OutputStream. Inside Java program, we often use
String object to store and pass file data, that's why we need a way to convert InputStream to String in Java. As a Java developer, just keep two things in mind while reading InputStream data as String :