File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Unable to update my data.. why is that so..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Unable to update my data.. why is that so..?" Watch "Unable to update my data.. why is that so..?" New topic
Author

Unable to update my data.. why is that so..?

Freya Tan
Ranch Hand

Joined: Apr 14, 2004
Posts: 45
i'm unable to update my data.. i'm not sure what have gone wrong.. Whenever i try to update, it would overwrite the first position of the data in the Textfile.. and then it's unable to display it.. (No matter which date i try to update, it's would definitely overwrite the first data)
Also how can i hightlight impt dates in a JList (as i'm doin a Calendar schedule) i want to have those date with appointment saved to be bold & in red colour..

Is there any kind soul out there that would help me.. I urgently need a reply.. Thanks.. Anxiously waiting 4 a reply..

Regards..
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

I'm going to try and explain something to you and I hope you understand that I am trying to help you here...
You need to stop asking so many questions in a single thread. The first part of this post...
i'm unable to update my data.. i'm not sure what have gone wrong.. Whenever i try to update, it would overwrite the first position of the data in the Textfile.. and then it's unable to display it.. (No matter which date i try to update, it's would definitely overwrite the first data)
...has nothing to do with Swing/AWT/JFC. Just because you are reading and writing to files from a Swing application doesn't make it a Swing problem. So this part of the question should really be seperated into a different post in the I/O and Streams forum. Now that doesn't mean repost this entire thread in that forum. That means, seperate your problems. You have 2 problems in this question.
Now your second problem is fine here in the Swing forum. So that one we can deal with. Here is a tutorial on JList. There is a link in that tutorial that talks about a Custom Cell Renderer. This is what you need to change the color of the items in your JList. I will let you find the link. That way I know you read the tutorial a little bit anyway.
Once you have started working on that part of your code, and are having problems, let's see what the problems are and go from there.
Again, concentrate on 1 issue at a time. It will make things easier for you. Especially since you are new to Java.


GenRocket - Experts at Building Test Data
Freya Tan
Ranch Hand

Joined: Apr 14, 2004
Posts: 45
Hi Mr Gregg,
I understand what u mean.. i would separate my problem the next time..
Now i need to know if anyone can reply me abt:

i'm unable to update my data.. i'm not sure what have gone wrong.. Whenever i try to update, it would overwrite the first position of the data in the Textfile.. and then it's unable to display it.. (No matter which date i try to update, it's would definitely overwrite the first data)

(becos u were saying i shouldn't post again in I/O & Stream)
So i'm not sure where i should post it now.. And i need to know what is the problem with my program asap.. Really sorry in creating so much troubles for u.. And a big Thanks..
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Your problem is because you are creating a new file everytime instead of appending to the current file. You need to take a look at the API for FileOutputStream.
public FileOutputStream(File file, boolean append) throws FileNotFoundException
Creates a file output stream to write to the file represented by the specified File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.

Hope that begins to help.
Freya Tan
Ranch Hand

Joined: Apr 14, 2004
Posts: 45
Sorry.. i dun quite understand.. can u show me an example..?
Thanks
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Originally posted by Freya Tan:
Sorry.. i dun quite understand.. can u show me an example..?
Thanks

Using your code...

That tells the OutputStream to write to the end of the outputFile instead of overwriting what is already there.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Since this is turning into an IO thread, I am going to move it to the I/O and Streams forum..
Freya Tan
Ranch Hand

Joined: Apr 14, 2004
Posts: 45
(that's in my code)

FileOutputStream out = new FileOutputStream(outputFile); PrintStream fileOutput = new PrintStream(out);
for (int x = 0; x < AppList.size(); x++) {
aObjt = (FindDay)AppList.get(x);
fileOutput.println(aObjt.getDate() + ";" + aObjt.getMonth() + ";" + aObjt.getYear() + ";" + aObjt.getTime() + ";" + aObjt.getAm() + ";" + aObjt.getApp());
}


if that is inside my code already, then how cum i'm still overwriting it..?? pls point out the sentence that i have mistake in.. Thank u
Freya Tan
Ranch Hand

Joined: Apr 14, 2004
Posts: 45
D:\Java Project\AppointmentPage.java:401: FileOutputStream(java.io.File,boolean) has private access in java.io.FileOutputStream
FileOutputStream out = new FileOutputStream(outputFile,true);
^
i have this error after adding the " (outputFile,True) ".. what is this error..?? i have nv seen it be.. any way to slove it..

Regards..
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

If you looked at the java documentation for java.io.FileOutputStream, you'd see that the constructor you are using is available only in SDK's 1.4 and later. Are you using an older SDK/JDK?


[How To Ask Questions On JavaRanch]
Freya Tan
Ranch Hand

Joined: Apr 14, 2004
Posts: 45
Thanks for replying..

Yes, i'm using a JDK 1.3.1 . anyway that i can change my coding to suit JDK 1.3.1 ... i have been trying for a few days and my deadline is tomorrow.. pls help me.. a big thanks to u..

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to update my data.. why is that so..?