Example usage for java.io BufferedReader readLine

List of usage examples for java.io BufferedReader readLine

Introduction

In this page you can find the example usage for java.io BufferedReader readLine.

Prototype

public String readLine() throws IOException 

Source Link

Document

Reads a line of text.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], Integer.parseInt(args[1]));
    GZIPOutputStream zip = new GZIPOutputStream(sock.getOutputStream());
    String line;//from  w  w w  .  java 2s .c  o m
    BufferedReader bis = new BufferedReader(new FileReader(args[2]));
    while (true) {
        line = bis.readLine();
        if (line == null)
            break;
        line = line + "\n";
        zip.write(line.getBytes(), 0, line.length());
    }
    zip.finish();
    zip.close();
    sock.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader("filename.txt"));

    String line = null;/* www  .j ava 2 s.co  m*/
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    URL url = new URL("http://hostname:80/index.html");

    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str;//from   w w  w .j a va2s.c  o  m
    while ((str = in.readLine()) != null) {
        System.out.println(str);
    }
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://localhost:1776");
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;/*  w  w  w  .j a  v  a  2  s.  c om*/
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    in.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);//from w  ww .j  av a  2 s .c  o  m
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close();
    System.setOut(console);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(stdin.readLine());
    BufferedReader in = new BufferedReader(new FileReader("Main.java"));
    String s, s2 = new String();
    while ((s = in.readLine()) != null)
        s2 += s + "\n";
    in.close();/* w ww.  j a  va 2  s  .c  om*/
    StringReader in1 = new StringReader(s2);
    int c;
    while ((c = in1.read()) != -1)
        System.out.print((char) c);
    BufferedReader in2 = new BufferedReader(new StringReader(s2));
    PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out")));
    int lineCount = 1;
    while ((s = in2.readLine()) != null)
        out1.println(lineCount++ + ": " + s);
    out1.close();
}

From source file:ProgressInputSample.java

public static void main(String args[]) {
    int returnValue = NORMAL;
    try {//  w ww  .j av a  2s . c  o  m
        FileInputStream fis = new FileInputStream("person.xml");
        JLabel filenameLabel = new JLabel("persion.xml", JLabel.RIGHT);
        Object message[] = { "Reading:", filenameLabel };
        ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis);
        InputStreamReader isr = new InputStreamReader(pmis);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
    } catch (Exception exception) {
        returnValue = PROBLEM;
    }
    System.exit(returnValue);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader("thefile.csv"));
    String line = null;/*w  w w . java  2 s .  c  o m*/

    while ((line = br.readLine()) != null) {
        String[] values = line.split(",");
        for (String str : values) {
            System.out.println(str);
        }
    }
    br.close();
}

From source file:ExecShellArgs.java

public static void main(String[] args) throws IOException {
    Runtime r = Runtime.getRuntime();
    String[] nargs = { "sh", "-c", "for i in 1 2 3; do echo $i; done" };
    Process p = r.exec(nargs);//from   w  ww.  j av  a  2s  .  co  m
    BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = is.readLine()) != null)
        System.out.println(line);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Socket sock = ssock.accept();
    ssock.close();//from w  w w  .  j a  v a 2s .  c om

    PrintStream pstream = new PrintStream(sock.getOutputStream());
    pstream.print("count? ");
    BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    String line = input.readLine();
    pstream.println("");
    int count = Integer.parseInt(line);
    for (int i = count; i >= 0; i--) {
        pstream.println(i);
    }
    pstream.close();
    sock.close();
}