• Post Reply Bookmark Topic Watch Topic
  • New Topic

writing to file

 
john omeara
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have created a jfilechooser in my program when the user clicks on the save button. What i want to do is then let the user specify the file (or create one) and then write to it via a fileoutput stream but i am having problems with my file references - the complier doesnt like the value file as the agument to the fileoutputstream constructor.
Anyone any ideas - my code is below:

int returnVal = fc.showSaveDialog(Serverside1.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
}
try
{

out = new FileOutputStream(file);

p = new PrintStream( out );

p.println ("This is written to a file");
p.close();
}
catch (Exception f)
{
System.err.println ("Error writing to file");
}
cheers people.
 
john omeara
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have managed to sort that now i hadnt declared file properly earlier in the code. However im getting the error message "Error writing to file" now. Anyone any ideas.
thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!