FileInputStream class

                                    
    java.lang.Object                               
     |                              
     |--java.io.InputStream                           
         |                          
         |--java.io.FileInputStream                       
                                    

A FileInputStream obtains input bytes from a file in a file system.

ConstructorSummary
FileInputStream(File file)Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.
FileInputStream(FileDescriptor fdObj)Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.
FileInputStream(String name)Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system.

ReturnMethodSummary
intavailable()Returns an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
voidclose()Closes this file input stream and releases any system resources associated with the stream.
FileChannelgetChannel()Returns the unique FileChannel object associated with this file input stream.
FileDescriptorgetFD()Returns the FileDescriptor object that represents the connection to the actual file in the file system being used by this FileInputStream.
intread()Reads a byte of data from this input stream.
intread(byte[] b)Reads up to b.length bytes of data from this input stream into an array of bytes.
intread(byte[] b, int off, int len)Reads up to len bytes of data from this input stream into an array of bytes.
longskip(long n)Skips over and discards n bytes of data from the input stream.
Revised from Open JDK source code

The following code reads one byte from the 'a.htm'


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws FileNotFoundException {
    FileInputStream file = null;
    byte x = -1;
    try {
      file = new FileInputStream("a.htm");
      x = (byte) file.read();
    } catch (FileNotFoundException f) {
      throw f;
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (file != null) {
          file.close();
        }
      } catch (IOException e) {
      }
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.