Java GUIs Input&OutputObjectStreams problem
Hey there
I am trying to make a GUI being able to read and write records. Ok, now suppose the following. Quote:
Quote:
Quote:
Quote:
Quote:
I didnt put the whole code of the program because is really big. Dont know if that tells you something. Can anybody imagine what could go wrong? Many thanks for your time manolakis. |
Try using a conviluted method of checking the presence of data in the file (it's really backwards, but will definitely override the isEmpty() method.
Code:
java.util.Scanner istream = new java.util.Scanner(new File("/path/to/file")); Code:
try { |
Hey there. Thanks for your reply
Ok, the way that i write to the file looks like: Quote:
|
Have you tried doing this with just a basic PrintStream?
|
The case is that I am restricted to use InputObjectStream.
I tried to compile the first piece of code that you gave but i got some errors |
or OutputObjectStream better
|
The first chunk of code gave you an error?! Weird...because I lifted that - directly - from a project of mine, and I know that code works. *shrug*
Are you using SUN Java, GCJ or another 3rd-party Java implementation? |
Sorry about my last post. I was really in a hurry and i didnt state things well
The fact is that i dont get error but i get some warnings for unsafe expressions Quote:
|
Ah! You are more than likely using a Java 5.0 (1.5) version compiler - I am using a 1.6 compiler - and for whatever reason, parameterized types were removed for java.util.ArrayList (as far as I know - there may be more) class.
To kill those warnings, try the declaration like so: Code:
... |
Ok that now works. I dont get any compilation error or warnings
Unfortunately when i execute i dont get any output Any suggestion? Many thanks |
Well, that's proving that the file's empty. Try filling the text file with a few lines of whatever.
|
ok I found no problem
|
Sweet deals. :)
Now, if you incorporate that to override the use of the isEmpty() function, does it work at all, or is the file still coming up as being empty (after data is being written to it)? |
ok, please let me take the chance to ask something
Lets say that we open a file, we write to it but we dont close that file and we exit (by using System.exit( 0 ); ). Could this cause a problem? |
If we were using a language such as C or C++, then I would say yes. But since Java runs in a VM (Virtual Machine), if we call System.exit(0), more than likely, the VM will call File.close() if there are any live out-streams.
|
All times are GMT -5. The time now is 03:29 PM. |