Board index » jbuilder » someone gotta help me or i'll cry

someone gotta help me or i'll cry


2004-05-23 11:20:25 PM
jbuilder18
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!!!!!
 
 

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" < XXXX@XXXXX.COM >wrote in message
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!!!!!


 

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,"{*word*76} 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" < XXXX@XXXXX.COM >wrote in
message news:40b0dc78$ XXXX@XXXXX.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" < XXXX@XXXXX.COM >wrote in message
news:40b0c11e$ XXXX@XXXXX.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!!!!!
>
>


 

{smallsort}

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 bugs.sun.com/bugdatabase/view_bug.do
You'll probably have to register to see the details.
Arth
"Double Dragon" < XXXX@XXXXX.COM >wrote in message
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();
}
 

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 bugs.sun.com/bugdatabase/view_bug.do
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());
}
 

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" < XXXX@XXXXX.COM >wrote in
message news:40b1134f$ XXXX@XXXXX.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 bugs.sun.com/bugdatabase/view_bug.do

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());
>}