File problems
hi,
I have this simple program for creating and wrting in a sequential file
[code][
import java.io.*;
class TestFileOutputStream {
public static void main (String arg[]) throws IOException {
//set up file and stream
File outFile = new File("sample1.data");
FileOutputStream outStream = new FileOutputStream(outFile);
//data to output
byte[] byteArray = {10, 20, 30, 40, 50, 60, 70, 80};
//write data to the stream
outStream.write(byteArray);
//output done, so close the stream
outStream.close();
}//main
}//TestFileOutputStream
/code]
It's not actually my program, I took it from the net but I'm using the same idea for another program and I implemented it in JCretor with j2se1.4.2:
I get the error:
"cannot resolve constructor File(java.lang.String)"
and
"cannot resolve constructor FileOutputSteam(File)"
which is really strange since the java documentation says that the constructor is exactly like that.
Can anybody define the problem
thank you,
Octavian
[1125 byte] By [
Octaviana] at [2007-10-2 17:41:13]

I think the problem is from jCreator or something 'cause I tried it on the MS-DOS and it worked. I tried my version of the program, doesn't work though. Gives me an error when I try to write a record to a file.
This is the code, mosts classes are for the form and the listeners but I have a class the implements Serializable
and the listner that writes to the file. It always gives me an exception.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import java.io.Serializable;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class BizCard extends JFrame
{
JButton add;
JTextField title;
JTextField name;
JTextField position;
JTextField tel1;
JTextField tel2;
JTextField email;
JTextField site;
File file;
ObjectOutputStream output;
public BizCard()
{
Container container = getContentPane();
container.setLayout(new FlowLayout());
title = new JTextField(30);
add = new JButton("ADD");
container.add(title);
container.add(add);
setSize(400,400);
setVisible(true);
ButtonListener buttonListener = new ButtonListener();
add.addActionListener(buttonListener);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private class Card implements Serializable
{
private String cardTitle;
public void setTitle(String newTitle)
{
cardTitle = newTitle;
}
public String getTitle()
{
return cardTitle;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Card record = new Card();
record.setTitle(title.toString());
//String fileName = "card.dat";
/*JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(BizCard.this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = fileChooser.getSelectedFile();
*/
File file = new File("card.dat");
try
{
FileOutputStream fileOut = new FileOutputStream(file);
//file = new File("card.dat");
output = new ObjectOutputStream(fileOut);
output.writeObject(record);
output.flush();
output.close();
}
catch(IOException ioException)
{
JOptionPane.showMessageDialog(BizCard.this, "Error Opening File");
}
//add files here
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void main(String []args)
{
BizCard biz = new BizCard();
biz.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
}
I'll keep working on it and try to find a solution