|
|

|  |
Java byte input streams The basic input stream is class InputStream. InputStream is an abstract class: it does not define how to read the data. The real functionality is provided by subclasses of InputStream . For file handling, the most important subclass of InputStream is FileInputStream. This is a class that can read a specified file from beginning to end. A Java program creates a new FileInputStream like this: File aFile = new File("readme.txt"); FileInputStream fis = new FileInputStream(aFile); Note that the FileInputStream needs to be supplied with a file object, not a simple filename, so we have to create a File object as well. You will often see this code shortened to: FileInputStream fis = new FileInputStream(new File("readme.txt")); The program can read the first byte of data in the file like this: Byte b = fis.read(); Each new call to the read() method reads the next byte in the file, until the end. Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |
|