import java.io.*; public class FileInputStreamExample { public static void main(String[] args) { try { FileInputStream fin = new FileInputStream("C:/example.txt"); // create FileInputStream object int i; while ((i = fin.read()) != -1) { // read the file byte by byte System.out.print((char) i); // print the content of the file } fin.close(); // Close the file } catch (IOException e) { e.printStackTrace(); } } }
import java.io.*; public class FileInputStreamExample { public static void main(String[] args) { try { FileInputStream fin = new FileInputStream("C:/example.jpg"); // create FileInputStream object byte[] bytes = new byte[fin.available()]; // create byte array to store the file content fin.read(bytes); // read the file and store it in the byte array fin.close(); // Close the file // Do something with the byte array, e.g. save to another file. } catch (IOException e) { e.printStackTrace(); } } }The package library for FileInputStream is java.io.