我正在写一个记事本克隆以了解更多关于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