Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Last active February 27, 2016 20:07
Show Gist options
  • Save AnnaBoro/c136f0a5089730135f3c to your computer and use it in GitHub Desktop.
Save AnnaBoro/c136f0a5089730135f3c to your computer and use it in GitHub Desktop.
InputStream
package lesson8.stream;
import java.io.*;
public class DemoStream2 {
public static void main (String[] args) {
InputStream inputStream = null;
String str = "Demo demo";
try {
inputStream = new ByteArrayInputStream(str.getBytes());
printStreamData(inputStream);
}
finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void printStreamData(InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);
try {
System.out.print(reader.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment