 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Double Dragon Guest
|
Posted: Sun May 23, 2004 3:20 pm Post subject: someone gotta help me or i'll cry |
|
|
please help me with this strange problem regarding i/o to a file. you gotta
read it carefully or else u wont get it!!!
my program operates as a reader form and a writer form. in normal
conditions, i can make(append) new entries whenever i want, and reader will
read it. But my program works same as Recordable CDs. Only the entries in
first writer session are read, but if i launch writer again and append
entries, the reader will still read only those entries made in first
session. although the file size of generated file seems to grow with each
entry. What's the solution????pls help me!!somebody!!!!!
|
|
| Back to top |
|
 |
Arthur Ore Guest
|
Posted: Sun May 23, 2004 5:16 pm Post subject: Re: someone gotta help me or i'll cry |
|
|
I think you are going to have to post some code.
Cut the code down to the minimum necessary to demonstrate the problem you
are having and also give exact steps as to what to run in what order to
cause your problem.
Arth
"Double Dragon" <mdoubledragon (AT) hotmail (DOT) com> wrote
| Quote: | please help me with this strange problem regarding i/o to a file. you
gotta
read it carefully or else u wont get it!!!
my program operates as a reader form and a writer form. in normal
conditions, i can make(append) new entries whenever i want, and reader
will
read it. But my program works same as Recordable CDs. Only the entries in
first writer session are read, but if i launch writer again and append
entries, the reader will still read only those entries made in first
session. although the file size of generated file seems to grow with each
entry. What's the solution????pls help me!!somebody!!!!!
|
|
|
| Back to top |
|
 |
Double Dragon Guest
|
Posted: Sun May 23, 2004 8:21 pm Post subject: Re: someone gotta help me or i'll cry |
|
|
Here's the code of my reader Class!
The main area of focus is are the two or three lines that write and read
object.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SugarReader
{
private ObjectInputStream input;
private SugarTime buffer;
public SugarReader(JDesktopPane mframe,JMenuBar bar,String name)
{
String fname=new String("DataFiles\"+name+"'s Sugar Report.dds");
File f=new File(fname);
if (!f.exists())
{
JOptionPane.showMessageDialog(null, "Your Record File Doesn't Exist",
"File I/O Error",
JOptionPane.ERROR_MESSAGE);
}
else
{
MainList l=new MainList();
try
{
input = new ObjectInputStream(new FileInputStream(fname));
while (true)
{
l.addList((SugarTime)input.readObject());
}
}
catch (IOException ex)
{
System.out.println("EOF");
}
catch (ClassNotFoundException ex)
{
System.out.println(ex.getMessage());
}
String[][] s=l.getString();
TableFrame t=new TableFrame(mframe,name,"Blood Sugar Report",s);
try
{
input.close();
}
catch (IOException ex)
{
System.out.println("Resources Not Released");
}
bar.getMenu(0).getItem(0).setEnabled(true);
}
}
}
----------------------------------------------------------------------------
------------------------------------------------
And here is the Writer Class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SugarForm extends BaseForm
{
private ObjectOutputStream output;
public SugarForm(final JDesktopPane mframe,final JMenuBar bar,final String
name,final String type)
{
super(mframe);
final String fname=new String("DataFiles\"+name+"'s Sugar Report.dds");
output=new ObjectOutputStream(new FileOutputStream(fname,true));
button[1].setEnabled(true);
button[1].setText("Submit");
button[1].addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (validateForms() && validateThis(tsvalue))
{
SugarTime s = new SugarTime(Integer.parseInt(tdate.getText()),
Integer.parseInt(tmonth.getText()),
Integer.parseInt(tyear.getText()),
Integer.parseInt(thour.getText()),
Integer.parseInt(tminute.getText()),
Float.parseFloat(tsvalue.getText()),
tfasting.getSelectedItem().toString());
try
{
output.writeObject(s);
}
catch (IOException ex)
{
JOptionPane.showMessageDialog(null,"Cannot Write To
File","File I/O Error",JOptionPane.ERROR_MESSAGE);
}
fileClose();
private void fileClose()
{
try
{
output.flush();
output.close();
}
catch (IOException ex)
{
System.out.println("Resources Not Released");
}
}
}
"Arthur Ore" <nospamthx_arthur (AT) nospamthx_arthurore (DOT) freeserve.co.uk> wrote in
message news:40b0dc78$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I think you are going to have to post some code.
Cut the code down to the minimum necessary to demonstrate the problem you
are having and also give exact steps as to what to run in what order to
cause your problem.
Arth
"Double Dragon" <mdoubledragon (AT) hotmail (DOT) com> wrote in message
news:40b0c11e$1 (AT) newsgroups (DOT) borland.com...
please help me with this strange problem regarding i/o to a file. you
gotta
read it carefully or else u wont get it!!!
my program operates as a reader form and a writer form. in normal
conditions, i can make(append) new entries whenever i want, and reader
will
read it. But my program works same as Recordable CDs. Only the entries
in
first writer session are read, but if i launch writer again and append
entries, the reader will still read only those entries made in first
session. although the file size of generated file seems to grow with
each
entry. What's the solution????pls help me!!somebody!!!!!
|
|
|
| Back to top |
|
 |
Arthur Ore Guest
|
Posted: Sun May 23, 2004 8:44 pm Post subject: Re: someone gotta help me or i'll cry |
|
|
Try adding an extra catch clause as shown in the code below.
I reckon you'll get a "java.io.StreamCorruptedException" error
In which case you are suffering from Sun's (not a) Bug 4293270
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4293270
You'll probably have to register to see the details.
Arth
"Double Dragon" <mdoubledragon (AT) hotmail (DOT) com> wrote
| Quote: | Here's the code of my reader Class!
The main area of focus is are the two or three lines that write and read
object.
SNIP/
try
{
input = new ObjectInputStream(new FileInputStream(fname));
while (true)
{
l.addList((SugarTime)input.readObject());
}
}
catch (IOException ex)
{
System.out.println("EOF");
}
catch (ClassNotFoundException ex)
{
System.out.println(ex.getMessage());
}
// try adding this |
catch (Exception ex)
{
ex.printStackTrace();
}
|
|
| Back to top |
|
 |
Arthur Ore Guest
|
Posted: Sun May 23, 2004 9:10 pm Post subject: Re: someone gotta help me or i'll cry |
|
|
Try changing your extra catch clause as shown in the code below.
I reckon you'll get a "java.io.StreamCorruptedException" error
In which case you are suffering from Sun's (not a) Bug 4293270
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4293270
You'll probably have to register to see the details.
Note the error message will be displayed before the details of your objects.
i.e., you'll have to scroll up to see the error if you've written a large
volume of data.
Arth
| Quote: | try
{
input = new ObjectInputStream(new FileInputStream(fname));
while (true)
{
l.addList((SugarTime)input.readObject());
}
}
catch (IOException ex)
{
System.out.println("EOF");
// ADD THIS LINE HERE |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!
ex.printStackTrace();
| Quote: | }
catch (ClassNotFoundException ex)
{
System.out.println(ex.getMessage());
}
|
|
|
| Back to top |
|
 |
Double Dragon Guest
|
Posted: Mon May 24, 2004 3:24 am Post subject: Re: someone gotta help me or i'll cry |
|
|
Sir!
It was the same thing as you pointed. I tried the workaround and
succeeded. Thankyou Very Much Sir! Maybe someday i'll be able to help Java
Community just as you did! Thanx Again!
"Arthur Ore" <nospamthx_arthur (AT) nospamthx_arthurore (DOT) freeserve.co.uk> wrote in
message news:40b1134f$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Try changing your extra catch clause as shown in the code below.
I reckon you'll get a "java.io.StreamCorruptedException" error
In which case you are suffering from Sun's (not a) Bug 4293270
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4293270
You'll probably have to register to see the details.
Note the error message will be displayed before the details of your
objects.
i.e., you'll have to scroll up to see the error if you've written a large
volume of data.
Arth
try
{
input = new ObjectInputStream(new FileInputStream(fname));
while (true)
{
l.addList((SugarTime)input.readObject());
}
}
catch (IOException ex)
{
System.out.println("EOF");
// ADD THIS LINE HERE
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!
ex.printStackTrace();
}
catch (ClassNotFoundException ex)
{
System.out.println(ex.getMessage());
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|