Thursday, February 29, 2024

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream;
import java.io.IOException;

public class ReadImageFile {
    public static void main(String[] args) {
        String imagePath = "yourImageFile.jpg"; // Replace with the actual image file path and name

        try (FileInputStream fileInputStream = new FileInputStream(imagePath)) {
            int byteRead;
            while ((byteRead = fileInputStream.read()) != -1) {
                System.out.print((char) byteRead);
            }
        } catch (IOException e) {
            System.err.println("Error reading the image file: " + e.getMessage());
        }
    }
}

No comments:

Post a Comment

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream; import java.io.IOException; public class ReadImageFile {     public static void main(String[] args) {       ...