GUIについてもっと学ぶために、メモ帳のクローンを書いています。私のプログラムは、次のコードでテキストファイルを作成します。
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(); opensText = opensText +""+読み取り;
フォーマットを文字列に保存する方法はありますか?