MarekMatias icon

VOP17.5

MarekMatias | PRO | 03/16/17 08:07:19 PM UTC | 0 ⭐ | 256 👁️ | Never ⏰ | []
Java |

930 B

|

None

|

0 👍

/

0 👎

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);
        }
 
 
    }
}

Comments