List of usage examples for java.io PrintStream PrintStream
public PrintStream(File file) throws FileNotFoundException
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept();//from w w w . j a v a2 s. co m PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
From source file:AnotherBeerServer.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); System.out.println("Listening"); Socket sock = ssock.accept(); ssock.close(); // no more connects PrintStream ps = new PrintStream(sock.getOutputStream()); // ask for count ps.print("count? "); BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream())); // read and parse it String line = input.readLine(); ps.println(""); int count = Integer.parseInt(line); for (int i = count; i >= 0; i--) { ps.println(i + " Java Source and Support."); }/*from w ww .j a v a 2s . co m*/ ps.close(); sock.close(); }
From source file:whois.java
public static void main(String[] args) { Socket theSocket;//from w ww . j a v a 2s. c o m DataInputStream theWhoisStream; PrintStream ps; try { theSocket = new Socket(hostname, port, true); ps = new PrintStream(theSocket.getOutputStream()); for (int i = 0; i < args.length; i++) ps.print(args[i] + " "); ps.print("\r\n"); theWhoisStream = new DataInputStream(theSocket.getInputStream()); String s; while ((s = theWhoisStream.readLine()) != null) { System.out.println(s); } } catch (IOException e) { System.err.println(e); } }
From source file:Redirect.java
public static void main(String args[]) throws Exception { PrintStream origOut = System.out; PrintStream origErr = System.err; InputStream stdin = null;//from w w w .j ava2 s . c o m stdin = new FileInputStream("Redirect.in"); PrintStream stdout = null; stdout = new PrintStream(new FileOutputStream("Redirect.out")); PrintStream stderr = null; stderr = new PrintStream(new FileOutputStream("Redirect.err")); origOut.println("1"); System.out.println("2"); origOut.println("3"); System.err.println("4"); origErr.println("5"); System.setIn(stdin); System.setOut(stdout); System.setErr(stderr); origOut.println("\nR"); System.out.println("T"); origOut.println("Tq"); System.err.println("Tqw"); origErr.println("Test"); origOut.println("\nRedirect: Round #3"); int inChar = 0; while (-1 != inChar) { try { inChar = System.in.read(); } catch (Exception e) { // Clean up the output and bail. origOut.print("\n"); break; } origOut.write(inChar); } stdin.close(); stdout.close(); stderr.close(); System.exit(0); }
From source file:Logging.java
public static void main(String args[]) throws Exception { FileOutputStream errors = new FileOutputStream("StdErr.txt", true); PrintStream stderr = new PrintStream(errors); PrintWriter errLog = new PrintWriter(errors, true); System.setErr(stderr);// w ww . jav a 2 s . com String query = "SELECT Name,Description,Qty,Cost,Sell_Price FROM Stock"; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Inventory"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String name = rs.getString("Name"); String desc = rs.getString("Description"); int qty = rs.getInt("Qty"); float cost = rs.getFloat("Cost"); } } catch (ClassNotFoundException e) { e.printStackTrace(errLog); } catch (SQLException e) { System.err.println((new GregorianCalendar()).getTime()); System.err.println("Thread: " + Thread.currentThread()); System.err.println("ErrorCode: " + e.getErrorCode()); System.err.println("SQLState: " + e.getSQLState()); System.err.println("Message: " + e.getMessage()); System.err.println("NextException: " + e.getNextException()); e.printStackTrace(errLog); System.err.println(); } stderr.close(); }
From source file:Finger.java
public static void main(String[] arguments) throws Exception { StringTokenizer split = new StringTokenizer(arguments[0], "@"); String user = split.nextToken(); String host = split.nextToken(); Socket digit = new Socket(host, 79); digit.setSoTimeout(20000);//from w w w . j av a 2 s .c om PrintStream out = new PrintStream(digit.getOutputStream()); out.print(user + "\015\012"); BufferedReader in = new BufferedReader(new InputStreamReader(digit.getInputStream())); boolean eof = false; while (!eof) { String line = in.readLine(); if (line != null) System.out.println(line); else eof = true; } digit.close(); }
From source file:MainClass.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 a va 2 s . co 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(); System.setOut(console); }
From source file:finger.java
public static void main(String[] args) { String hostname;//from w ww . ja v a 2 s . c o m Socket theSocket; DataInputStream theFingerStream; PrintStream ps; try { hostname = args[0]; } catch (Exception e) { hostname = "localhost"; } try { theSocket = new Socket(hostname, port, true); ps = new PrintStream(theSocket.getOutputStream()); for (int i = 1; i < args.length; i++) ps.print(args[i] + " "); ps.print("\r\n"); theFingerStream = new DataInputStream(theSocket.getInputStream()); String s; while ((s = theFingerStream.readLine()) != null) { System.out.println(s); } } catch (IOException e) { System.err.println(e); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { System.setProperty("javax.net.ssl.keyStore", "mykeystore"); System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut"); SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept();/* www.java2 s . c o m*/ PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
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", 8888); OutputStream outs = s.getOutputStream(); PrintStream out = new PrintStream(outs); InputStream ins = s.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(ins)); out.println("Hi,How are u!"); out.println(""); String line = null;// www . j a v a2 s.c om while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); out.close(); }