List of usage examples for java.io InputStream read
public abstract int read() throws IOException;
From source file:InputStreamEnumerator.java
public static void main(String args[]) throws IOException { int c;//from w w w .j ava 2 s . co m Vector<String> files = new Vector<String>(); files.addElement("c:\\autoexec.bat"); files.addElement("c:\\config.sys"); InputStreamEnumerator e = new InputStreamEnumerator(files); InputStream input = new SequenceInputStream(e); while ((c = input.read()) != -1) { System.out.print((char) c); } input.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String serverName = System.getProperty("WHOIS_SERVER", DEFAULT_HOST); InetAddress server = null;/* ww w . j a v a 2 s.c om*/ server = InetAddress.getByName(serverName); Socket theSocket = new Socket(server, DEFAULT_PORT); Writer out = new OutputStreamWriter(theSocket.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = theSocket.getInputStream(); InputStream in = new BufferedInputStream(theSocket.getInputStream()); int c; while ((c = in.read()) != -1) System.out.write(c); }
From source file:Main.java
public static void main(String[] args) throws Exception { int i = 0;/*from ww w . java2 s . c o m*/ // new input stream created InputStream is = new FileInputStream("C://test.txt"); // read till the end of the stream while ((i = is.read()) != -1) { // convert integer to character char c = (char) i; // print System.out.println("Character Read: " + c); } is.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { URL url = new URL("http://www.google.com"); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); InputStream inStrm = httpCon.getInputStream(); System.out.println("\nContent at " + url); int ch;//from www . j a v a 2 s.com while (((ch = inStrm.read()) != -1)) System.out.print((char) ch); inStrm.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ResultSet rset = null;/*w ww .j a va 2 s . c o m*/ InputStream stream = rset.getBinaryStream(1); ByteArrayOutputStream output = new ByteArrayOutputStream(); int a1 = stream.read(); while (a1 >= 0) { output.write((char) a1); a1 = stream.read(); } Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray()); output.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { int c;/*from w w w. jav a 2 s . com*/ URL hp = new URL("http", "www.java2s.com", 80, "/"); URLConnection hpCon = hp.openConnection(); if (hpCon.getContentLength() > 0) { InputStream input = hpCon.getInputStream(); int i = hpCon.getContentLength(); while (((c = input.read()) != -1) && (--i > 0)) { System.out.print((char) c); } input.close(); } else { System.out.println("No Content Available"); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "tock.usno.navy.mil"; Socket theSocket = new Socket(hostname, 13); InputStream timeStream = theSocket.getInputStream(); StringBuffer time = new StringBuffer(); int c;//from www .j av a 2 s . c o m while ((c = timeStream.read()) != -1) time.append((char) c); String timeString = time.toString().trim(); System.out.println("It is " + timeString + " at " + hostname); }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww. ja va 2s. c om*/ // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // get the input stream of the process and print it InputStream in = p.getInputStream(); for (int i = 0; i < in.available(); i++) { System.out.println(in.read()); } // wait for 10 seconds and then destroy the process Thread.sleep(10000); p.destroy(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:FileInputOutputExample.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("in.txt"); OutputStream os = new FileOutputStream("out.txt"); int c;//w w w. j ava 2 s. c om while ((c = is.read()) != -1) { System.out.print((char) c); os.write(c); } is.close(); os.close(); }
From source file:Main.java
public static void main(String[] args) { try {// w w w.j ava 2 s. c o m // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // get the error stream of the process and print it InputStream error = p.getErrorStream(); for (int i = 0; i < error.available(); i++) { System.out.println(error.read()); } // wait for 10 seconds and then destroy the process Thread.sleep(10000); p.destroy(); } catch (Exception ex) { ex.printStackTrace(); } }