Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package teln;
- import static java.lang.System.out;
- import java.io.IOException;
- import java.io.InputStream;
- public class StreamReader {
- private StreamReader() {
- }
- StreamReader(InputStream inputStream) throws IOException {
- printEachLine(inputStream);
- }
- private void printEachLine(InputStream inputStream) {
- char ch = 0;
- StringBuilder sb = new StringBuilder();
- out.println("lines..");
- boolean eol = false;
- do {
- try {
- ch = (char) inputStream.read();
- } catch (IOException ex) {
- out.println(sb); //hmm, doesn't seem to print...or prints nothing
- }
- sb.append(ch);
- if ((ch == 10)) {
- out.print(sb); //prints everything but last line
- sb = new StringBuilder();
- }
- } while (!eol);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment