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[] args) throws Exception { // create input streams InputStream is = new FileInputStream("C://test.txt"); FilterInputStream fis = new BufferedInputStream(is); // reads and prints filter input stream System.out.println((char) fis.read()); System.out.println((char) fis.read()); // mark invoked at this position fis.mark(0);/*from w w w . j a v a 2s. co m*/ System.out.println("mark() invoked"); System.out.println((char) fis.read()); System.out.println((char) fis.read()); // reset() repositioned the stream to the mark fis.reset(); System.out.println("reset() invoked"); System.out.println((char) fis.read()); System.out.println((char) fis.read()); }
From source file:Main.java
public static void main(String[] args) throws Exception { // create input streams InputStream is = new FileInputStream("C://test.txt"); FilterInputStream fis = new BufferedInputStream(is); // reads and prints BufferedReader System.out.println((char) fis.read()); System.out.println((char) fis.read()); // mark invoked at this position fis.mark(0);// w w w . ja v a2 s. c om System.out.println("mark() invoked"); System.out.println((char) fis.read()); System.out.println((char) fis.read()); // reset() repositioned the stream to the mark fis.reset(); System.out.println("reset() invoked"); System.out.println((char) fis.read()); System.out.println((char) fis.read()); }
From source file:Main.java
public static void main(String[] args) { try {/*w w w . j av a2s . c o m*/ OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); // write something os.write('A'); // flush the stream os.flush(); // close the stream but it does nothing os.close(); // read what we wrote System.out.println((char) is.read()); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File aFile = new File("primes.txt"); FileInputStream inFile = new FileInputStream(aFile); FileChannel inChannel = inFile.getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(1024); buf.position(buf.limit());/*from w w w. ja v a 2s . co m*/ while (true) { if (buf.remaining() < 8) { if (inChannel.read(buf.compact()) == -1) { break; } buf.flip(); } int strLength = (int) buf.getDouble(); if (buf.remaining() < 2 * strLength) { if (inChannel.read(buf.compact()) == -1) { break; } buf.flip(); } byte[] strChars = new byte[2 * strLength]; buf.get(strChars); if (buf.remaining() < 8) { if (inChannel.read(buf.compact()) == -1) { break; } buf.flip(); } System.out.println(strLength); System.out.println(ByteBuffer.wrap(strChars).asCharBuffer()); System.out.println(buf.getLong()); } inFile.close(); }
From source file:Main.java
public static void main(String[] args) { try {//from w ww. ja v a 2 s .c o m OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); // write something os.write('A'); // flush the stream but it does nothing os.flush(); // write something else os.write('B'); // read what we wrote System.out.println(is.available()); os.close(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); CertificateFactory certFact = CertificateFactory.getInstance("X.509"); CertPath path = certFact.generateCertPath(Arrays.asList(new Certificate[] { cert })); }
From source file:Main.java
public static void main(String[] args) throws Exception { String fromFileName = "from.txt"; String toFileName = "to.txt"; FileChannel in = new FileInputStream(fromFileName).getChannel(); FileChannel out = new FileOutputStream(toFileName).getChannel(); ByteBuffer buff = ByteBuffer.allocateDirect(32 * 1024); while (in.read(buff) > 0) { buff.flip();/*from ww w.j a va 2 s. co m*/ out.write(buff); buff.clear(); } in.close(); out.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String fromFileName = args[0]; String toFileName = args[1];/* w w w. j a va 2 s. com*/ FileChannel in = new FileInputStream(fromFileName).getChannel(); FileChannel out = new FileOutputStream(toFileName).getChannel(); ByteBuffer buff = ByteBuffer.allocate(32 * 1024); while (in.read(buff) > 0) { buff.flip(); out.write(buff); buff.clear(); } in.close(); out.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectInputStream ois = new ObjectInputStream( new GZIPInputStream(new FileInputStream(new File("user.dat")))); User admin = (User) ois.readObject(); User foo = (User) ois.readObject();/* w w w.j av a 2 s . co m*/ ois.close(); System.out.println("Admin = [" + admin + "]"); System.out.println("Foo = [" + foo + "]"); }
From source file:Main.java
public static void main(String[] args) throws Exception { byte[] buffer = new byte[6]; // create input streams InputStream is = new FileInputStream("C://test.txt"); FilterInputStream fis = new BufferedInputStream(is); // returns number of bytes read to buffer int i = fis.read(buffer); // prints/* ww w . j a v a 2 s .co m*/ System.out.println("Number of bytes read: " + i); // for each byte in buffer for (byte b : buffer) { // converts byte to character char c = (char) b; System.out.println("Character read: " + c); } }