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 { FileInputStream fis = new FileInputStream("test.txt"); FileChannel fc = fis.getChannel(); long startRegion = 0; long endRegion = fc.size(); MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, startRegion, endRegion); while (mbb.hasRemaining()) { System.out.print((char) mbb.get()); }//from www . j a va2s . c om fis.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); int byteNum = bis.available(); System.out.println(byteNum);// w w w.ja va 2 s . co m bis.close(); byteNum = bis.available(); System.out.println(byteNum); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:\\test.txt"); DataInput in = new DataInputStream(is); DataInputStream.readUTF(in);// w w w. j a va 2s . c om }
From source file:Main.java
public static void main(String[] args) throws Exception { // new input stream created InputStream is = new FileInputStream("C://test.txt"); // invoke available int i = is.available(); // number of bytes available is printed System.out.println(i);//from w ww. j a v a 2 s . c o m // releases any system resources associated with the stream is.close(); // throws io exception on available() invocation i = is.available(); System.out.println(i); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fIn = new FileInputStream("test.txt"); FileChannel fChan = fIn.getChannel(); long fSize = fChan.size(); ByteBuffer mBuf = ByteBuffer.allocate((int) fSize); fChan.read(mBuf, 10);//from w w w . j a v a 2 s .com mBuf.rewind(); for (int i = 0; i < fSize; i++) { System.out.print((char) mBuf.get()); } fChan.close(); fIn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fIn = new FileInputStream("test.txt"); FileChannel fChan = fIn.getChannel(); long fSize = fChan.size(); ByteBuffer mBuf = ByteBuffer.allocate((int) fSize); fChan.read(mBuf);/*from ww w. ja v a 2s .c om*/ mBuf.rewind(); for (int i = 0; i < fSize; i++) { System.out.print((char) mBuf.get()); } fChan.close(); fIn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Properties p = new Properties(); p.load(new FileInputStream("test.txt")); p.store(new FileOutputStream("t.txt"), "no comments"); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = new byte[4]; FileInputStream fis = new FileInputStream("C://test.txt"); // read bytes to the buffer int i = fis.read(bs); System.out.println("Number of bytes read: " + i); // for each byte in buffer for (byte b : bs) { // converts byte to character char c = (char) b; System.out.println(c);/* ww w. ja va 2 s.com*/ } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("a.dat"); InflaterInputStream iis = new InflaterInputStream(fin); FileOutputStream fout = new FileOutputStream("b.dat"); for (int c = iis.read(); c != -1; c = iis.read()) { fout.write(c);//from w w w . j av a 2 s .c om } fout.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = new byte[4]; FileInputStream fis = new FileInputStream("C://test.txt"); // read bytes to the buffer int i = fis.read(bs, 2, 1); System.out.println("Number of bytes read: " + i); // for each byte in buffer for (byte b : bs) { // converts byte to character char c = (char) b; if (b == 0) { c = '-'; }// ww w . j av a 2s.c o m System.out.println(c); } }