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 {
    File file = new File(".");

    if (file.isDirectory()) {
        String[] files = file.list();
        for (int i = 0; i < files.length; i++)
            System.out.println(files[i]);
    } else {/*from   w  w w .j a  va  2 s  . co m*/
        FileReader fr = new FileReader(file);
        BufferedReader in = new BufferedReader(fr);
        String line;
        while ((line = in.readLine()) != null)
            System.out.println(line);
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s;//from w  w w  .j a  v a  2 s .  com
    while ((s = in.readLine()) != null && s.length() != 0)
        System.out.println(s);
    // An empty line or Ctrl-Z terminates the program
}

From source file:Main.java

public static void main(String argv[]) throws Exception {
    String line;//from www . java  2  s  . com
    Process p = Runtime.getRuntime().exec("psql -U username -d dbname -h serverhost -f scripfile.sql");
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = input.readLine()) != null) {
        System.out.println(line);
    }
    input.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("keyfile"));
    DESKeySpec ks = new DESKeySpec((byte[]) ois.readObject());
    SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
    SecretKey key = skf.generateSecret(ks);

    Cipher c = Cipher.getInstance("DES/CFB8/NoPadding");
    c.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec((byte[]) ois.readObject()));
    CipherInputStream cis = new CipherInputStream(new FileInputStream("ciphertext"), c);
    BufferedReader br = new BufferedReader(new InputStreamReader(cis));
    System.out.println(br.readLine());
}

From source file:InputOutputDemoStandardInputOutput.java

public static void main(String[] a) throws Exception {

    //Write characters to standard output and standard error:
    System.out.println("std output");
    System.err.println("std error");
    //Read characters from standard input (the keyboard):
    System.out.print("Type some characters and press Enter: ");
    BufferedReader bisr = new BufferedReader(new InputStreamReader(System.in));
    String response = bisr.readLine();
    System.out.println("You typed: '" + response + "'");
    //Read a byte from standard input (the keyboard):
    System.out.print("Type one character and press Enter: ");
    byte b = (byte) System.in.read();
    System.out.println("First byte of your input is: " + b);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String srcFile = "test.txt";
    BufferedReader br = new BufferedReader(new FileReader(srcFile));
    String text = null;// w  w  w .  j  a  v  a2 s  .c om

    while ((text = br.readLine()) != null) {
        System.out.println(text);
    }
    br.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("infilename"), "UTF8"));
    String str = in.readLine();
    System.out.println(str);/*from w w w  . j  a  v  a2 s  . c  o m*/
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    Hashtable map = new Hashtable();
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    String line;/*from w w  w  .  j a  v a2  s  . c  om*/
    while ((line = br.readLine()) != null) {
        processLine(line, map);
    }
    Enumeration e = map.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + map.get(key));
    }
}

From source file:WordCount.java

public static void main(String args[]) throws IOException {

    Hashtable map = new Hashtable();
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    String line;//from  w ww.ja va  2  s  .com
    while ((line = br.readLine()) != null) {
        processLine(line, map);
    }
    Enumeration e = map.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + map.get(key));
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("infilename"), "8859_1"));
    String str = in.readLine();
    System.out.println(str);//  ww w. jav a  2  s . c om
}