List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "from java2s.com"; StringReader sr = new StringReader(s); // create new buffered reader BufferedReader br = new BufferedReader(sr); // Destination source is created CharBuffer target = CharBuffer.allocate(s.length()); // ready is invoked to test if character stream is ready if (br.ready()) { br.read(target);/*w w w.j av a 2s . com*/ } System.out.print(target.array()); }
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 v a 2s . co m*/ 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:MainClass.java
License:asdf
public static void main(String[] args) throws IOException { try {/*from ww w. j a v a2 s .c om*/ BufferedReader in4 = new BufferedReader(new StringReader("asdf")); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out"))); int lineCount = 1; String s = null; while ((s = in4.readLine()) != null) out1.println(lineCount++ + ": " + s); out1.close(); } catch (EOFException e) { System.err.println("End of stream"); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "localhost"; Socket theSocket = new Socket(hostname, 7); BufferedReader networkIn = new BufferedReader(new InputStreamReader(theSocket.getInputStream())); BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(theSocket.getOutputStream()); System.out.println("Connected to echo server"); while (true) { String theLine = userIn.readLine(); if (theLine.equals(".")) break; out.println(theLine);/*from w w w . java2 s .c o m*/ out.flush(); System.out.println(networkIn.readLine()); } networkIn.close(); out.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { InetAddress server = InetAddress.getByName("localhost"); BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket theSocket = new DatagramSocket(); while (true) { String theLine = userInput.readLine(); if (theLine.equals(".")) break; byte[] data = theLine.getBytes(); DatagramPacket theOutput = new DatagramPacket(data, data.length, server, 99999); theSocket.send(theOutput);// w w w.j a v a 2s .c o m } }
From source file:Main.java
public static void main(String... args) throws IOException { URL url = new URL("http://java2s.com"); InputStream is = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line;/* w w w. j a v a 2s .c o m*/ while ((line = br.readLine()) != null) sb.append(line + System.lineSeparator()); br.close(); System.out.print(sb.toString()); }
From source file:MainClass.java
public static void main(String args[]) { try {/*from w w w.ja v a 2s . co m*/ System.out.print("Enter your name: "); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(reader); String name = in.readLine(); System.out.println("Hello, " + name + ". Enter three ints..."); int[] values = new int[3]; double sum = 0.0; for (int i = 0; i < values.length; i++) { System.out.print("Number " + (i + 1) + ": "); String temp = in.readLine(); values[i] = Integer.parseInt(temp); sum += values[i]; } System.out.println("The average equals " + sum / values.length); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "from java2s.com"; // create and assign a new string reader StringReader sr = new StringReader(s); // create new buffered reader BufferedReader br = new BufferedReader(sr); // reads and prints BufferedReader int value = 0; while ((value = br.read()) != -1) { // skips a character br.skip(1);// w w w . j a va2s . c o m System.out.print((char) value); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); URL url = new URL("https://www.verisign.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line;/* w ww. jav a 2 s. c o m*/ while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); br.close();//w ww .j a va2s . c o m // creates error br.read(); }