可能重複:
Writing multiline JTextArea content into file文件保存爲文本區域的概率
我已經寫代碼,保存文件從我的文本區域的問題是,它可以節省這一切在在新的文本文件一行,而不是在我的文字box.below是我的代碼
String text = dna_ta.getText();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("./"));
int actionDialog = chooser.showSaveDialog(this);
if (actionDialog == JFileChooser.APPROVE_OPTION)
{
BufferedWriter out = null;
try {
File fileName = new File(chooser.getSelectedFile() + "");
if(fileName == null)
return;
if(fileName.exists())
{
actionDialog = JOptionPane.showConfirmDialog(this,
"Replace existing file?");
if (actionDialog == JOptionPane.NO_OPTION)
return;
}
out = new BufferedWriter(new FileWriter(fileName));
out.write(text);
out.close();
在我的T
內線方面是如下
asd
aaaaaa
但在我的文本文件保存它的如下
asdaaaaaa
我無法揣摩出我已經錯將其保存爲相同的格式,在我textarea.thank你
請注意,我刪除了[tag:netbeans]標記並添加了[tag:swing]標記,因爲此問題與NetBeans無關,並且都與Swing和IO有關。 –