Last active
February 27, 2016 20:07
-
-
Save AnnaBoro/c136f0a5089730135f3c to your computer and use it in GitHub Desktop.
InputStream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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