read(): This method is available in the java.io.FileInputStream class of Java.
Syntax:
int java.io.FileInputStream.read() throws IOException
This method reads a byte of data from this input stream. This method blocks if no input is yet available.
Parameters: NA
Returns: the next byte of data, or -1 if the end of the file is reached.
Throws:
IOException - if an I/O error occurs.
Approach
Java
import java.io.File;import java.io.FileInputStream;import java.io.IOException;public class FileInputStreamread {public static void main(String[] args) throws IOException {String pathname = "D:\\hello.txt";File file = new File(pathname);FileInputStream fileInputStream =new FileInputStream(file);System.out.println(fileInputStream.read());fileInputStream.close();}}
Output:
-1
No comments:
Post a Comment