メモ帳作成で困っています。
テキストを保存したいのですが、テキストの保存自体はできるのですがテキストの中身が反映されません。
どこに何を入れればしっかりと保存できるのでしょうか?
アドバイスよろしくお願いします。
###ソースコード
//保存メニューをクリックしたとき
JMenuItem menuItem_5 = new JMenuItem("保存");
menuItem_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser filechooser = new JFileChooser();
int selected = filechooser.showSaveDialog(null);
if (selected == JFileChooser.APPROVE_OPTION){
File file = filechooser.getSelectedFile();
System.out.println(filechooser.getName(file));
try{ BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(textPane.getText()); bw.close(); }catch(FileNotFoundException e1){ System.out.println(e1); }catch(IOException e2){ System.out.println(e2); } } } });
###環境詳細
Eclipse,Java8(デフォルト),標準VM
回答1件
あなたの回答
tips
プレビュー