FileWriter writer = null;
JFileChooser chooser = new JFileChooser();
int result = chooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION) return;
try {
alamatfile = chooser.getSelectedFile().getAbsolutePath();
alamat = alamatfile.replace('\\', '/');
} catch (Exception e) {
System.exit(0);}
try {
writer = new FileWriter(alamat+".txt");
sectext.write(writer);
} catch (IOException exception) {
System.err.println("Save failed");
} finally {
if (writer != null) {
try {
writer.close();
JOptionPane.showMessageDialog(null, "Message has been saved");
} catch (IOException exception) {
System.err.println("Error closing writer");
}}
}
Minggu, 17 Juli 2011
Menyimpan String dari jTextArea ke dalam File
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar
Terima kasih atas komentar Anda :)