List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
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.j ava 2s .co m while ((str = rd.readLine()) != null) { System.out.println(str); } rd.close(); }
From source file:Main.java
public static void main(String[] args) { try {//from w w w .ja v a 2 s . co m BufferedReader input = new BufferedReader(new FileReader(args[0])); ArrayList list = new ArrayList(); String line; while ((line = input.readLine()) != null) { list.add(line); } input.close(); Collections.reverse(list); PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); for (Iterator i = list.iterator(); i.hasNext();) { output.println((String) i.next()); } output.close(); } catch (IOException e) { System.err.println(e); } }
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;// ww w .j ava 2 s . c om 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:MainClass.java
public static void main(String args[]) { try {/*from www.ja v a 2 s . c om*/ // Create a file reader FileReader fr = new FileReader(args[0]); // Create a buffered reader BufferedReader br = new BufferedReader(fr); // Create a stream tokenizer StreamTokenizer st = new StreamTokenizer(br); // Process tokens while (st.nextToken() != StreamTokenizer.TT_EOF) { switch (st.ttype) { case StreamTokenizer.TT_WORD: System.out.println(st.lineno() + ") " + st.sval); break; case StreamTokenizer.TT_NUMBER: System.out.println(st.lineno() + ") " + st.nval); break; default: System.out.println(st.lineno() + ") " + (char) st.ttype); } } // Close file reader fr.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
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();// w w w. j a va 2 s . 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:Converter.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream(new File("input.txt")); BufferedReader in = new BufferedReader(new InputStreamReader(fis, "SJIS")); FileOutputStream fos = new FileOutputStream(new File("output.txt")); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos, "UTF8")); int len = 80; char buf[] = new char[len]; int numRead;//from ww w. ja v a 2 s. com while ((numRead = in.read(buf, 0, len)) != -1) out.write(buf, 0, numRead); out.close(); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File archivo = new File("c:/Java_Dev/run.bat"); FileReader fr = new FileReader(archivo); BufferedReader br = new BufferedReader(fr); Vector<String> lines = new Vector<String>(); String line;//from w w w .ja v a 2 s .c om while ((line = br.readLine()) != null) { lines.add(line); } JOptionPane.showMessageDialog(null, new JScrollPane(new JList(lines))); fr.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);// ww w . jav a 2 s . 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
License:asdf
public static void main(String[] arges) throws Exception { InetAddress addr = InetAddress.getByName(null); Socket sk = new Socket(addr, 8888); BufferedReader in = new BufferedReader(new InputStreamReader(sk.getInputStream())); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sk.getOutputStream())), true); out.println("asdf"); System.out.println(in.readLine()); }
From source file:Main.java
public static void main(String args[]) throws Exception { ServerSocket serverSocket = new ServerSocket(8080); Socket socket = serverSocket.accept(); InputStream inStream = socket.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); String str = null;/*from w w w .ja va2 s . c o m*/ while ((str = reader.readLine()) != null) { System.out.println(str); } }