List of usage examples for java.io BufferedReader readLine
public String readLine() throws IOException
From source file:MainClass.java
public static void main(String[] args) throws IOException { // 1. Reading input by lines: BufferedReader in = new BufferedReader(new FileReader("IOStreamDemo.java")); String s, s2 = new String(); while ((s = in.readLine()) != null) s2 += s + "\n"; in.close();/*from ww w. java2 s.c o m*/ }
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. ja va 2 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:Redirecting.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 w w. j ava2s.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(); // Remember this! System.setOut(console); }
From source file:Main.java
public static void main(String[] args) throws IOException { ExecutorService service = Executors.newFixedThreadPool(4); BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in)); String line;/* ww w . j av a 2s . c om*/ while ((line = buffer.readLine()) != null) { service.execute(new Worker(line)); } }
From source file:ReverseConsoleInput.java
public static void main(String args[]) throws Exception { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); // Read and process lines from console String s;/*from w w w . j a v a 2 s .c o m*/ while ((s = br.readLine()) != null) { StringBuffer sb = new StringBuffer(s); sb.reverse(); System.out.println(sb); } isr.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a line:"); System.out.println(stdin.readLine()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { System.setProperty("javax.net.ssl.trustStore", "clienttrust"); SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault(); Socket s = ssf.createSocket("127.0.0.1", 5432); SSLSession session = ((SSLSocket) s).getSession(); Certificate[] cchain = session.getPeerCertificates(); System.out.println("The Certificates used by peer"); for (int i = 0; i < cchain.length; i++) { System.out.println(((X509Certificate) cchain[i]).getSubjectDN()); }/*from w w w.j a va2 s. co m*/ System.out.println("Peer host is " + session.getPeerHost()); System.out.println("Cipher is " + session.getCipherSuite()); System.out.println("Protocol is " + session.getProtocol()); System.out.println("ID is " + new BigInteger(session.getId())); System.out.println("Session created in " + session.getCreationTime()); System.out.println("Session accessed in " + session.getLastAccessedTime()); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String x = in.readLine(); System.out.println(x); in.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int port = 2000; ServerSocket srv = new ServerSocket(port); // Wait for connection from client. Socket socket = srv.accept(); BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); String str;/*ww w . ja va 2 s . c om*/ while ((str = rd.readLine()) != null) { System.out.println(str); } rd.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL yahoo = new URL("http://www.yahoo.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine;/*from w w w.ja va 2 s . c o m*/ while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL myURL = new URL("http://www.google.com"); BufferedReader so = new BufferedReader(new InputStreamReader(myURL.openStream())); while (true) { String output = so.readLine(); if (output != null) { System.out.println(output); } else {/*from www . j a v a 2s . c o m*/ break; } } so.close(); }