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:Main.java
public static void main(String[] argv) throws Exception { ReadableByteChannel channel = new FileInputStream("infile").getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(10); int numRead = 0; while (numRead >= 0) { buf.rewind();/*from w w w. j a va 2 s . c o m*/ numRead = channel.read(buf); buf.rewind(); // Read bytes from ByteBuffer; see also for (int i = 0; i < numRead; i++) { byte b = buf.get(); } } }
From source file:Main.java
public static void main(String[] args) { String srcFile = "test.txt"; try (PushbackInputStream pis = new PushbackInputStream(new FileInputStream(srcFile))) { byte byteData; while ((byteData = (byte) pis.read()) != -1) { System.out.print((char) byteData); pis.unread(byteData);//from w w w . j a v a 2s . co m // Reread the byte we unread byteData = (byte) pis.read(); System.out.print((char) byteData); } } catch (Exception e2) { e2.printStackTrace(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream("test"); ObjectInputStream ois = new ObjectInputStream(fis); Object o = ois.readObject();/*from w ww . ja va 2s . co m*/ if (!(o instanceof String)) { System.out.println("Unexpected data in file"); System.exit(-1); } String data = (String) o; System.out.println("Got message " + data); o = ois.readObject(); if (!(o instanceof byte[])) { System.out.println("Unexpected data in file"); System.exit(-1); } byte origDigest[] = (byte[]) o; MessageDigest md = MessageDigest.getInstance("SHA"); md.update(data.getBytes()); if (MessageDigest.isEqual(md.digest(), origDigest)) System.out.println("Message is valid"); else System.out.println("Message was corrupted"); }
From source file:Main.java
public static void main(String[] args) throws IOException { InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); int length = dis.available(); byte[] buf = new byte[length]; dis.readFully(buf, 4, 5);//from w ww. j a va2s.com for (byte b : buf) { char c = '0'; if (b != 0) { c = (char) b; } System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileChannel fc = new FileInputStream("data.txt").getChannel(); ByteBuffer buff = ByteBuffer.allocate(BSIZE); fc.read(buff);// w ww .j a va 2s . co m buff.flip(); while (buff.hasRemaining()) System.out.print((char) buff.get()); }
From source file:ZipReader.java
public static void main(String[] args) throws Exception { ZipInputStream zis = null;// w w w . j a va 2s. c om FileInputStream fis = new FileInputStream(args[0]); zis = new ZipInputStream(fis); ZipEntry ze; while ((ze = zis.getNextEntry()) != null) System.out.println(ze.getName()); }
From source file:Main.java
public static void main(String[] args) { InputStream fileInputStream;//from w w w . ja v a 2s. com try { fileInputStream = new FileInputStream("c:/a.txy"); Runtime runTime = Runtime.getRuntime(); runTime.getLocalizedInputStream(fileInputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { boolean bool = false; InputStream inStream = new FileInputStream("c:/test.txt"); // input stream is converted to buffered input stream BufferedInputStream bis = new BufferedInputStream(inStream); // returns true if mark() and read() supports bool = bis.markSupported();/*from w w w .j a v a 2 s . co m*/ System.out.println("Support for mark() and reset() : " + bool); }
From source file:Main.java
License:asdf
public static void main(String[] args) { String dataSourceFile = "asdf.txt"; try (FileInputStream fin = new FileInputStream(dataSourceFile)) { byte byteData; while ((byteData = (byte) fin.read()) != -1) { System.out.print((char) byteData); }//from w ww. jav a 2s .c om } catch (FileNotFoundException e) { ; } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream is = new FileInputStream("c:/test.txt"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos, 200); }