MarekMatias

VOP17.5

Mar 16th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package com.Marek;
  2.  
  3. import java.io.*;
  4.  
  5. /**
  6.  * Store object and arrays in a file
  7.  * write a program that stores an array of the six int  values 1 - 6, a date object for the current time
  8.  * And a double value 10.5 into the file named Exercise17_05.dat
  9.  */
  10.  
  11.  
  12. public class Main {
  13.  
  14.     public static void main(String[] args) throws IOException {
  15.         int myIntArray[] = {1, 2, 3, 4, 5, 6};
  16.         double theDoubletoOutput = 10.5;
  17.  
  18.         try (// Create an output stream for file Exercise17_05.dat
  19.              ObjectOutputStream objectOutputStream =
  20.                      new ObjectOutputStream(new FileOutputStream("Exercise17_05.dat"))) {
  21.            
  22.             //Write array of int, date and a double to the .dat file
  23.             objectOutputStream.writeObject(myIntArray);
  24.             objectOutputStream.writeObject(new java.util.Date());
  25.             objectOutputStream.writeDouble(theDoubletoOutput);
  26.         }
  27.  
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment