Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing to a file

Status
Not open for further replies.

zumbar

Programmer
Jun 9, 2003
1
IE
does anyone know why this doesnt work

public void saveDialog()
{
JFileChooser openChooser= new JFileChooser("C:\\");
int returnValue1 = openChooser.showSaveDialog(this);
File sf = openChooser.getSelectedFile();

try
{

String gettext = myTextArea.getText();
//BufferedWriter bw = new BufferedWriter(new Filewriter(sf,true));
PrintWriter bw = new PrintWriter(new FileWriter("myText.txt"));
//System.out.println(gettext);
bw.write("myText.txt");

}
catch(IOException e)
{
System.out.println("main():" + e);
}
}
 
Try this:

public void saveDialog()
{
/*...*/
try
{
PrintWriter bw = new PrintWriter(new FileWriter("myText.txt"));
bw.write("myText.txt");
bw.flush();
}
catch(IOException e)
{
System.out.println("main():" + e);
}
}

 
after the flush() you will also need to close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top