Socket Programming Question:
Shows how to save a Date object to a file?
Answer:
Code Sample 1: SaveDate.java
import java.io.*;
import java.util.Date;
public class SaveDate {
public static void main(
String argv[]) throws Exception {
FileOutputStream fos =
new FileOutputStream("date.out");
ObjectOutputStream oos =
new ObjectOutputStream(fos);
Date date = new Date();
oos.writeObject(date);
oos.flush();
oos.close();
fos.close();
}
}
import java.io.*;
import java.util.Date;
public class SaveDate {
public static void main(
String argv[]) throws Exception {
FileOutputStream fos =
new FileOutputStream("date.out");
ObjectOutputStream oos =
new ObjectOutputStream(fos);
Date date = new Date();
oos.writeObject(date);
oos.flush();
oos.close();
fos.close();
}
}
Previous Question | Next Question |
Shows how to read a serialized object and print its information? | Overview of Object Serialization |