Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Marek;
- import java.io.*;
- /**
- * Store object and arrays in a file
- * write a program that stores an array of the six int values 1 - 6, a date object for the current time
- * And a double value 10.5 into the file named Exercise17_05.dat
- */
- public class Main {
- public static void main(String[] args) throws IOException {
- int myIntArray[] = {1, 2, 3, 4, 5, 6};
- double theDoubletoOutput = 10.5;
- try (// Create an output stream for file Exercise17_05.dat
- ObjectOutputStream objectOutputStream =
- new ObjectOutputStream(new FileOutputStream("Exercise17_05.dat"))) {
- //Write array of int, date and a double to the .dat file
- objectOutputStream.writeObject(myIntArray);
- objectOutputStream.writeObject(new java.util.Date());
- objectOutputStream.writeDouble(theDoubletoOutput);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment