Note that there are some explanatory texts on larger screens.

plurals
  1. POstore and add new line + date stamp to document from java app
    primarykey
    data
    text
    <p>Hello i have coded an application to write something from a TextArea into a text document but the problem is,he does write it,but it dosen't store it and when i open it again,to write more in the same text document(or create a new document). How could i do that ? And a aditional information that i would require is how can i add date stamp alonside the text i enter in text document? Here is my code : </p> <pre><code>import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileWriter; import java.io.IOException; public class Write extends JFrame { JTextArea text; public Write() { this.setTitle("Writerz!"); setSize(400, 200); setResizable(false); setLocation(370, 150); setLayout(null); JLabel lbltitlu = new JLabel("Insert your text here"); lbltitlu.setBounds(85, 5, 120, 25); this.add(lbltitlu); final JTextArea text = new JTextArea(); text.setSize(199, 199); text.setBounds(85, 65, 120, 25); add(text); JButton btn = new JButton("Add text"); btn.setSize(99, 99); btn.setBounds(125, 125, 120, 25); add(btn); ActionListener listenerbtn = new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO auto- generated method String actionbtn = arg0.getActionCommand(); if (actionbtn.equals("Add text")) { Adauga(text.getText()); } } }; btn.addActionListener(listenerbtn); } public void Adauga(String text) { String filename = "test.txt"; FileWriter writer = null; try { writer = new FileWriter(filename); writer.write(text); } catch (IOException exception) { System.err.println("Save oops"); } finally { if (writer != null) { try { writer.close(); } catch (IOException exception) { System.err.println("Error closing writer"); exception.printStackTrace(); } } } } } </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload