FileInputStream Class

Package: java.io

The FileInputStream class connects an input stream to an input file. You won’t often use this class to read directly from an input file. Instead, you’ll use it with other classes such as BufferedInputStream and DataInputStream.

CrossRef.eps The FileInputStream class is one of many Java I/O classes that use streams. For more information, see Streams (Overview).

Constructors

Constructor

Description

FileInputStream File (File file)

Creates a file input stream from the specified object. It throws FileNotFoundException if the file doesn’t exist or if it’s a directory rather than a file.

FileInputStream(String path)

Creates a file input stream from the specified pathname. It throws FileNotFoundException if the file doesn’t exist or if it’s a directory rather than a file.

Creating a FileInputStream object

You can create FileInputStream from a File object like this:

File f;

FileInputStream fstream;

f = new File(“myfile.txt”);

fstream = new FileInputStream(f);

If you prefer, you can skip the File object and create the FileInputStream directly from a path string:

FileInputStream fstream;

fstream = new FileInputStream(“myfile.txt”);

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.