我正在寫一個記事本克隆以瞭解更多關於guis的知識。我的程序用代碼創建一個文本文件:將格式化添加到java格式化程序
try {
formatter = new Formatter(fileName+".txt");
formatter.format(contents);
formatter.close();
JOptionPane.showMessageDialog(null, "File saved as "+fileName +".txt");
} catch (Exception e){
JOptionPane.showMessageDialog(null, "Error writing to file");
}
如何保持我的文本格式?我從JTextArea檢索文件:
String contents = text.getText();
但基本上我失去了所有的格式。當我從文件中讀取文本時,我在字之間返回空格:
String reading = sc.next(); openedText = openedText +「」+閱讀;
無論如何存儲格式在字符串?
你在說什麼樣的格式? – 2011-06-11 20:56:43
什麼是「內容」?什麼是'sc'? – Atreys 2011-06-11 21:04:41