fileInputStream.read
时间: 2023-10-25 09:04:56 浏览: 102
The `read()` method in `FileInputStream` class is used to read a byte of data from the input stream. It returns the next byte of data, or -1 if the end of the file is reached.
Syntax:
```
public int read() throws IOException
```
Example usage:
```
FileInputStream fis = new FileInputStream("input.txt");
int data = fis.read();
while(data != -1) {
System.out.print((char)data);
data = fis.read();
}
fis.close();
```
In this example, the `FileInputStream` reads from a file named "input.txt". The `read()` method is used inside a loop to read each byte of data from the file and print it as a character. The loop continues until the end of the file is reached (`read()` returns -1), at which point the file input stream is closed.
阅读全文