Example usage for java.io BufferedReader close

List of usage examples for java.io BufferedReader close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

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

    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str;/*ww  w.ja  v  a  2s . co m*/
    while ((str = in.readLine()) != null) {
        System.out.println(str);
    }
    in.close();
}

From source file:MainClass.java

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

    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(PORT);
    Socket s = ss.accept();/*from www . j  ava2s .c om*/
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String line = null;
    while (((line = in.readLine()) != null)) {
        System.out.println(line);
    }
    in.close();
    s.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    SocketFactory factory = SSLSocketFactory.getDefault();
    Socket socket = factory.createSocket("127.0.0.1", 8080);

    OutputStream outputStream = socket.getOutputStream();
    PrintWriter out = new PrintWriter(outputStream);
    out.print("GET / HTTP/1.0\r\n\r\n");
    out.flush();/* w ww .jav a2 s.  c  o m*/
    InputStream inputStream = socket.getInputStream();
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader in = new BufferedReader(inputStreamReader);

    String line;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    out.close();
    in.close();
    socket.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);//w w  w  .  j  a va  2s .co  m
    OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

    writer.write("value=1&anotherValue=1");
    writer.flush();
    String line;
    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }
    writer.close();
    reader.close();

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();/*w ww  .j av a2  s  .  co m*/
    PdfContentByte cb = writer.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    BufferedReader reader = new BufferedReader(new FileReader("a.txt"));
    String line;
    while ((line = reader.readLine()) != null) {
        ct.addText(new Phrase(line + "\n"));
    }
    reader.close();
    ct.setSimpleColumn(36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36, 18,
            Element.ALIGN_JUSTIFIED);
    int status = ColumnText.START_COLUMN;
    while (ColumnText.hasMoreText(status)) {
        status = ct.go();
        ct.setYLine(PageSize.A4.height() - 36);
        document.newPage();
    }
    document.close();
}

From source file:MainClass.java

public static void main(String[] a) {

    FileReader fr;//  www.  j ava2s .  c  om
    try {
        fr = new FileReader(new File("yourFile.txt"));
        BufferedReader br = new BufferedReader(fr);
        String line = br.readLine();
        while (line != null) {
            System.out.println(line);
            line = br.readLine();
        }
        br.close();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String input = reader.readLine();

    double number = Double.parseDouble(input);

    System.out.println(input + ":" + Math.sqrt(number));

    reader.close();
}

From source file:LowerCaseReader.java

public static void main(String[] args) throws Exception {
    String fileName = "test.txt";
    LowerCaseReader lcr = new LowerCaseReader(new FileReader(fileName));
    int c = -1;/*  w  w  w. ja va 2 s  . co  m*/
    while ((c = lcr.read()) != -1) {
        System.out.print((char) c);
    }
    lcr.close();
    BufferedReader br = new BufferedReader(new LowerCaseReader(new FileReader(fileName)));
    String str = null;
    while ((str = br.readLine()) != null) {
        System.out.println(str);
    }
    br.close();
}

From source file:CollateApp.java

public static void main(String args[]) {
    if (args.length != 1) {
        System.out.println("Usage: java CollateApp file");
        System.exit(0);// ww  w . j  a v a2s. c o m
    }
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector keyVector = new Vector();
    try {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line = in.readLine()) != null)
            keyVector.addElement(collator.getCollationKey(line));
        in.close();
    } catch (Exception ex) {
        System.out.println(ex);
        System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
        keys[i] = (CollationKey) keyVector.elementAt(i);
}

From source file:CollateApp.java

public static void main(String args[]) {
    if (args.length != 1) {
        System.out.println("Usage: java CollateApp file");
        System.exit(0);//from   w  w  w . j a va2  s  .  c  o m
    }
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector<Object> keyVector = new Vector<Object>();
    try {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line = in.readLine()) != null)
            keyVector.addElement(collator.getCollationKey(line));
        in.close();
    } catch (Exception ex) {
        System.out.println(ex);
        System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
        keys[i] = (CollationKey) keyVector.elementAt(i);
}