Note that there are some explanatory texts on larger screens.

plurals
  1. POBuffered writer writes but doesnt have the line spacing
    primarykey
    data
    text
    <p>I am using a <code>JTextArea</code>. When using buffered writer to write to file it doesn't write correctly.</p> <p>This is what I write in the field</p> <pre><code> Hello My name is alexander Goodye! </code></pre> <p>What i get is</p> <pre><code> HelloMy name is alexanderGoodbye! </code></pre> <p>Can anyone help? Here is my code.</p> <pre><code>package main; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; public class TextEditor { static final JTextArea textArea = new JTextArea(20, 50); static final JFileChooser saveDirectory = new JFileChooser("save"); public static void start(){ JFrame f = new JFrame("Text editor"); JButton saveButton = new JButton("Save"); JButton loadButton = new JButton("load"); JPanel editor = new JPanel(); JPanel buttons = new JPanel(); buttons.add(saveButton); buttons.add(loadButton); //Button setup saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { save(); } }); //END editor.add(textArea); f.setLayout(new BorderLayout(3,3)); f.add(buttons, BorderLayout.PAGE_START); f.add(textArea); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.pack(); f.setVisible(true); } public static void save(){ File dir; saveDirectory.showDialog(null, "Save file"); dir = saveDirectory.getSelectedFile(); System.out.println(dir); try { FileWriter fw = new FileWriter(dir); BufferedWriter bw = new BufferedWriter(fw); bw.write(textArea.getText()); bw.close(); System.out.println("Done!"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); JOptionPane.showMessageDialog(null, e); } } } </code></pre> <p>Any help is greatly appreciated.</p> <p>EDIT 1: Installed np++ and the text file displays perfectly. why and how can i possibly make the file compatible with windows standard notepad.exe</p>
    singulars
    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.
 

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