List of usage examples for java.io FileInputStream FileInputStream
public FileInputStream(FileDescriptor fdObj)
FileInputStream
by using the file descriptor fdObj
, which represents an existing connection to an actual file in the file system. From source file:Copy.java
public static void main(String[] args) throws Exception { FileInputStream fis = null;//from w w w. j a v a 2 s .com FileOutputStream fos = null; fis = new FileInputStream(args[0]); fos = new FileOutputStream(args[1]); int byte_; while ((byte_ = fis.read()) != -1) fos.write(byte_); }
From source file:MainClass.java
public static void main(String args[]) { try {//from w w w.j ava 2 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[] args) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream("Main.class")); int start = in.readInt(); if (start != 0xcafebabe) { System.out.println("not valid"); }/*from w w w . j a v a2 s . c om*/ in.close(); System.out.println(in.readUnsignedShort() + "/" + in.readUnsignedShort()); }
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 . j a va 2s.c o m*/ // 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 IOException { FileInputStream fis = new FileInputStream("C:/test.txt"); LineNumberInputStream lnis = new LineNumberInputStream(fis); int i;/*from w w w.j a va2s.co m*/ while ((i = lnis.read()) != -1) { char c = (char) i; System.out.println("Character read: " + c); int j = lnis.available(); System.out.println("Available bytes: " + j); } }
From source file:Main.java
public static void main(String args[]) throws Exception { InputStream fis = new FileInputStream("a.exe"); byte[] buffer = new byte[1024]; MessageDigest complete = MessageDigest.getInstance("MD5"); int numRead;/*from w ww . j a v a 2 s . c o m*/ do { numRead = fis.read(buffer); if (numRead > 0) { complete.update(buffer, 0, numRead); } } while (numRead != -1); fis.close(); byte[] b = complete.digest(); String result = ""; for (int i = 0; i < b.length; i++) { result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1); } System.out.println(result); }
From source file:FileDeflater.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("a.dat"); FileOutputStream fout = new FileOutputStream("b.dat"); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c);/*w w w .j a va2s .c o m*/ } dos.close(); fin.close(); }
From source file:Main.java
public static void main(String args[]) throws IOException { FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java"); FileInputStream f2 = new FileInputStream("FileIOApp.java"); SequenceInputStream inStream = new SequenceInputStream(f1, f2); boolean eof = false; int byteCount = 0; while (!eof) { int c = inStream.read(); if (c == -1) eof = true;// ww w . j a v a 2 s. c o m else { System.out.print((char) c); ++byteCount; } } System.out.println(byteCount + " bytes were read"); inStream.close(); f1.close(); f2.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { int i;//from ww w . j av a 2s. c om FileInputStream fis = new FileInputStream("C:/test.txt"); InputStreamReader isr = new InputStreamReader(fis); // read till the end of the file while ((i = isr.read()) != -1) { // int to character char c = (char) i; System.out.println("Character Read: " + c); } isr.close(); }
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 w ww . j a v a2s .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()); }