List of usage examples for java.io BufferedInputStream BufferedInputStream
public BufferedInputStream(InputStream in)
BufferedInputStream
and saves its argument, the input stream in
, for later use. From source file:Main.java
public static void main(String[] args) throws Exception { InputStream inStream = new FileInputStream("c:/test.txt"); BufferedInputStream bis = new BufferedInputStream(inStream); int byteNum = bis.available(); System.out.println(byteNum);/*from www. j a v a 2 s . c o m*/ bis.close(); byteNum = bis.available(); System.out.println(byteNum); }
From source file:Main.java
public static void main(String[] args) throws Exception { URLConnection urlc = new URL("http://www.google.com").openConnection(); BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream()); int byteRead; while ((byteRead = buffer.read()) != -1) { System.out.println((char) byteRead); }//from w w w . java 2 s. c o m buffer.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InputStream is = Main.class.getResourceAsStream("image.gif"); BufferedInputStream bis = new BufferedInputStream(is); byte[] byBuf = new byte[10000]; int byteRead = bis.read(byBuf, 0, 10000); Image img = Toolkit.getDefaultToolkit().createImage(byBuf); }
From source file:MainClass.java
public static void main(String args[]) { try {//from w w w .ja va2 s. co m FileInputStream fis = new FileInputStream(args[0]); BufferedInputStream bis = new BufferedInputStream(fis); int i; while ((i = bis.read()) != -1) { System.out.println(i); } fis.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("Bean.xml"))); Bean bean = (Bean) decoder.readObject(); decoder.close();/*from w ww . j a va 2 s.co m*/ System.out.println("ID = " + bean.getId()); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream inStream = new FileInputStream("c:/test.txt"); BufferedInputStream bis = new BufferedInputStream(inStream); // read number of bytes available int numByte = bis.available(); // byte array declared byte[] buf = new byte[numByte]; // read byte into buf , starts at offset 2, 3 bytes to read bis.read(buf, 2, 3);//from w w w .ja va2s. c om // for each byte in buf for (byte b : buf) { System.out.println((char) b + ": " + b); } }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream iStream = new FileInputStream("c:/test.txt"); BufferedInputStream bis = new BufferedInputStream(iStream); // read and print characters one by one System.out.println((char) bis.read()); System.out.println((char) bis.read()); System.out.println((char) bis.read()); // mark is set on the input stream bis.mark(0);/*from ww w . ja v a2 s.c o m*/ System.out.println((char) bis.read()); // reset is called bis.reset(); // read and print characters System.out.println((char) bis.read()); System.out.println((char) bis.read()); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/ReadFile.txt"); FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin); while (bin.available() > 0) { System.out.println((char) bin.read()); }/* w ww . j av a 2s.c om*/ bin.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/ReadFile.txt"); FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin); byte[] contents = new byte[1024]; int bytesRead = 0; String strFileContents;// w ww . ja v a 2s . c o m while ((bytesRead = bin.read(contents)) != -1) { strFileContents = new String(contents, 0, bytesRead); System.out.print(strFileContents); } bin.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream inStream = new FileInputStream("c:/test.txt"); BufferedInputStream bis = new BufferedInputStream(inStream); // read until a single byte is available while (bis.available() > 0) { // get the number of bytes available Integer nBytes = bis.available(); System.out.println("Available bytes = " + nBytes); // read next available character char ch = (char) bis.read(); // print the read character. System.out.println("The character read = " + ch); }/*from ww w. ja v a 2 s. c o m*/ }