PDA

View Full Version : Java - Writing to File Help Needed!



deeadeed
12-06-2007, 03:36 AM
I am working on a project and need it to write certain data (user input from a form) into a file. I created the following write class but it only creates the txt file and doesnt write.

private void requestJButtonActionPerformed (ActionEvent event)
{

Writer fw = null;

try
{

final FileWriter outputFile = new FileWriter("customer.txt");
final BufferedWriter outputBuffer = new BufferedWriter(outputFile);
final PrintWriter printstream = new PrintWriter(outputBuffer);
fw.write( phoneJTextField + "," + postcodeJTextField );
}
catch ( IOException e ) {
System.err.println( "Cannot write to file" );
}

finally {
if ( fw != null )
try { fw.close(); } catch ( IOException e ) { }
}


}



any ideas + how to correct it please help.

Thanks

Twey
12-06-2007, 10:27 AM
What are phone and postcode? They should be strings, but from the naming it looks as though they're JTextFields.