Welcome to Dream.In.Code
Become a Java Expert!

Join 149,614 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,867 people online right now. Registration is fast and FREE... Join Now!




My file input output problem

 
Reply to this topicStart new topic

My file input output problem

Cypherz00
20 Aug, 2007 - 06:23 PM
Post #1

New D.I.C Head
*

Joined: 20 Aug, 2007
Posts: 3


My Contributions
ok a new even simpler question. The code below is meant to create a folder, output information into that folder, and write and array into it.
CODE

        ArrayList tempArrayz = new ArrayList();
        tempArrayz = (ArrayList) newArray.get(0);
        File f = new File("WorkSpace");
        f.mkdir();
        File f1 = new File(f.getAbsolutePath(), user.getUserName());
        f1.mkdir();
        File fileo = new File(f1.getAbsolutePath(), user.getUserName() +  ".dat");

        try {
        ObjectOutputStream ou = new ObjectOutputStream(new
        FileOutputStream(fileo));
        ou.writeObject(tempArrayz);
        catch{
                   (Exception e) {
            System.out.println(e.toString());
}
}


Below is the code to read from that and print out the array size

    public void readTheFile()
    {
        
        boolean stopReading = false;
        int numberOfRead = 0;
        while (!stopReading) {
            try {
    
                numberOfRead++;
                File f = new File("WorkSpace");
                f.mkdir();
                File f1 = new File(f.getAbsolutePath(), user.getUserName());
                f1.mkdir(); //make the username folder
                File fileo = new File(f1.getAbsolutePath(),
                                      user.getUserName() + counter + ".dat");
System.out.println(oi.readObject());
                ObjectInputStream oi = new ObjectInputStream(new
                        FileInputStream(fileo));
                    array = (ArrayList) oi.readObject();
                   System.out.println(array.size());
                oi.close();
                stopReading = true;
            } catch (Exception e) {
               if (numberOfRead == 2) {
                    stopReading = true;
                }
    
            }
        }


anyone tell me what im doing wrong? When it prints out the array object before assigning it to my input stream it returns
finaldiary.User@1758500


AHhh!! help

~Admin Edit: please use [code] tags like in the example.
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: My File Input Output Problem
21 Aug, 2007 - 03:47 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
what does the code do? does it create the directory or the file? does it save the data? is it a saving or retrieval error? more info if you want help.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:29AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month