|
|||||||||||||||||||
• Example. The following program can be used to read a file of array objects from disk. It can be used to display the array values stored by the previous sample program. | |||||||||||||||||||
import java.io.*; public class App { public static void main(String[] args) { // Local variables and object references. File fd; // Get the path name from the user. System.out.print(“Enter the file’s complete path name: “); // Try to read data from the input stream. try // Open an input stream for the file. in = new ObjectInputStream(new FileInputStream(fd)); // This loop reads a array objects from the stream and displays try // Close the stream. in.close(); // Catch an IOException if one is thrown. catch (IOException e) { // Catch an ClassNotFoundException if one is thrown. catch (ClassNotFoundException e) { |
|||||||||||||||||||