Java Byte Stream FileInputStream/FileOutputStream

FileInputStream

FileInputStream Constructors

Constructor Description
FileInputStream(String filePath) throws FileNotFoundException Creates an input stream for the file specified by filepath.
FileInputStream(File fileObj) throws FileNotFoundException Creates an input stream for the file specified by fileObj.
FileInputStream(FileDescriptor fdObj) throws SecurityException Creates a file system input stream that represents an existing connection through fdObj.

FileInputStream Methods

Method Description
int available() throws IOException Returns the number of bytes currently available to read.
int close() throws IOException Closes the InputStream.
int read() throws IOException Reads one byte from the InputStream and returns it as an int value.
int read(byte buf[]) throws IOException Reads up to the size of buf[] from the InputStream, stores it in buf, and returns the number of bytes read.
int read(byte buf[], int offset, int numBytes) throws IOException Reads numBytes from the InputStream, stores them starting at offset in buf[], and returns the number of bytes read.
int skip(long numBytes) throws IOException Skips the bytes specified by numBytes and returns the number of skipped bytes.
protected void finalize() Calls the close() method when there are no more references.
FileChannel getChannel() Returns the unique FileChannel object of the FileInputStream.
FileDescriptor getFD() Returns the FileDescriptor object for the actual file connection in the FileInputStream.

FileInputStream Example

Preparing.

FileOutputStream

FileOutputStream Constructors

Constructor Description
FileOutputStream(String filepath) throws FileNotFoundException Creates an OutputStream for the file specified by filepath.
FileOutputStream(String filepath, boolean append) throws FileNotFoundException Creates an OutputStream for the specified file. The append argument sets append mode when outputting.
FileOutputStream(File fileObj) throws FileNotFoundException Creates an OutputStream for the file specified by fileObj.
FileOutputStream(File fileObj, boolean append) throws FileNotFoundException Creates an OutputStream for the file specified by fileObj. The append argument sets append mode when outputting.
FileOutputStream(FileDescriptor fdObj) throws NullPointerException Creates a file system OutputStream that represents an existing connection through fdObj.

FileOutputStream Methods

Method Description
void close() throws IOException Closes the OutputStream.
void flush() throws IOException Outputs the remaining OutputStream data in the buffer.
void write(int i) throws IOException Outputs the lower 8 bits of integer i.
void write(byte buf[]) throws IOException Outputs the contents of buf.
void write(byte buf[], int index, int size) throws IOException Outputs size bytes starting from index in buf.
FileChannel getChannel() Returns the unique FileChannel object associated with the OutputStream.
FileDescriptor getFD() Returns the FileDescriptor object associated with the OutputStream.

FileOutputStream Example

Preparing.