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}