Results 1 to 5 of 5

Thread: Files

  1. #1
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Cool Files

    hello to everybody i ve the following example and i want to make files with the objects of the class "dokimi" but the compiler it has another ideas:) in the txt file instead of the account and the name it show me this:


    java.io.NotSerializableException(Vx η†5 xr java.io.ObjectStreamExceptiondΓδk9ϋί xr java.io.IOExceptionl€sde%π« xr java.lang.ExceptionΠύ xr java.lang.ThrowableΥΖ5'9wΈΛ L causet Ljava/lang/Throwable;L
    detailMessaget Ljava/lang/String;[
    stackTracet [Ljava/lang/StackTraceElement;xpq ~ t ofthalmiatreio.dokimiur [Ljava.lang.StackTraceElement;F*<<ύ"9 xp sr java.lang.StackTraceElementa ...

  2. #2
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    my code is :

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package ofthalmiatreio;
    import java.io.*;

    /**
    *
    * @author kris
    */
    public class dokimi {

    private int account;
    private String name;

    public dokimi(int acc, String name){

    this.account=acc;
    this.name=name;
    }

    public void setAcc(int acc){

    this.account=acc;
    }
    public int getAcc(){

    return account;
    }

    public void setName(String name){

    this.name=name;
    }
    public String getName(){

    return name;
    }

    public static void main(String args[]) throws IOException
    {
    try{
    // Create file
    File file = new File("c:\\test.txt");
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
    dokimi a=new dokimi(1237,"Christos");
    out.writeObject(a);
    //Close the output stream
    out.close();
    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }



    }

    has anyone any idea for what happen??

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:

    Java Code:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    And read the documentation for java.io.Serializable.

    db

  5. #5
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    Ok i didn t know this trick. I find something for my problem. I ve written this to my code and it works in a way.

    public class dokimi implements Serializable{
    ...
    }

    I found it in the google but i dont exactly understand what it does.
    The results is txt files is the following:
    ¬ν sr ofthalmiatreio.dokimi…i uΝ'ΖV I accountL namet Ljava/lang/String;xp Υt Christos

    So the above results is the properly results in the case of file writing?
    Also i cant find the reason why in the txt it doesnt show the numper of account.

    Anyone who can help???

Similar Threads

  1. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  2. Writing to files within jar files
    By erhart in forum Advanced Java
    Replies: 0
    Last Post: 02-04-2008, 02:50 AM
  3. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 04:43 AM
  4. how to convert mpeg files to .wav files
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:14 AM
  5. convert xls files into pdf files
    By bbq in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •