Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you have to Serialize the <code>Person</code> object by implementing <a href="http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html" rel="nofollow">java.io.Serializable</a> From the API doc, <a href="http://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html" rel="nofollow">ObjectInputStream</a></p> <pre><code> ObjectInputStream is used to recover those objects previously serialized. </code></pre> <p>Code Below(Main function is same as yours:</p> <pre><code> public static void main(String[] args) throws IOException, ClassNotFoundException { FileOutputStream fos = new FileOutputStream("src/main/resources/Test.txt"); ObjectOutputStream oos = new ObjectOutputStream(fos); Person person = new Person("B1234","Roshane","Nolan","male","Spanish Town",new Date(), "B2134","B3214",150.0,5.11); oos.writeObject(person); oos.flush(); oos.close(); //READING FROM THE FILE FileInputStream fis = new FileInputStream("src/main/resources/Test.txt"); ObjectInputStream ois = new ObjectInputStream(fis); Person object = (Person) ois.readObject(); System.out.println(object.toString()); } </code></pre> <p>Person Class</p> <pre><code> import java.util.Date; public class Person implements java.io.Serializable{ String arg1,arg2,arg3,arg4,arg5,arg6,arg7; Double d1,d2; Date date1; public Person(String string, String string2, String string3, String string4, String string5, Date date, String string6, String string7, double d, double e) { this.arg1=string; this.arg2=string2; this.arg3=string3; this.arg4=string4; this.arg5=string5; this.arg6=string6; this.arg7=string7; this.d1=d; this.d2=e; this.date1=date; // TODO Auto-generated constructor stub } @Override public String toString() { return "Person:"+this.arg1+":"+this.arg2+":"+this.arg3+":"+this.arg4+":"+this.arg5+":"+this.arg6+":"+this.arg7+":"+this.d1+":"+this.d2+":"+this.date1; } } </code></pre> <p>Output :</p> <pre><code>Person:B1234:Roshane:Nolan:male:Spanish Town:B2134:B3214:150.0:5.11:Sun Apr 14 23:11:27 CDT 2013 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload