import java.awt.BorderLayout; import java.awt.FileDialog; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.logging.Level; import java.util.logging.Logger; import java.lang.String; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JTextArea; /** * */ public class Notepad extends JFrame{FileInputStream fis; Notepad(String title){super(title); final JTextArea ta=new JTextArea(""); add(ta,BorderLayout.CENTER); /** * @param args the command line arguments */ JMenuBar md=new JMenuBar(); setJMenuBar(md); JMenu File=new JMenu("Файл"); md.add(File); JMenuItem open=new JMenuItem("Открыть"); File.add(open); JMenuItem save=new JMenuItem("Сохранить как"); File.add(save); JMenu sav=new JMenu("Сохранить"); File.add(sav); open.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){try { FileDialog fo = new FileDialog(new JFrame(), "Открыть", FileDialog.LOAD); fo.show(); String fn=fo.getDirectory()+fo.getFile(); if (fn==null) {return; } else { } DataInputStream InS = new DataInputStream(new BufferedInputStream(new FileInputStream(fn))); try { Reader r = new InputStreamReader(InS, "UTF-8"); char cbuf[] = new char[InS.available()]; int len; while ((len = r.read(cbuf)) != 0) { String str = new String(cbuf, 0, len); ta.setText(str); r.close(); }} catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); }catch(ArrayIndexOutOfBoundsException ex){System.out.println("ex");} } catch (FileNotFoundException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }); save.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){ FileDialog fs=new FileDialog(new Frame(),"Сохранить как",FileDialog.SAVE); fs.show(); String nfs=fs.getDirectory()+fs.getFile();try { DataOutputStream IoS = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(nfs+".txt"))); String fil=ta.getText(); byte[] buff=fil.getBytes(); try { IoS.write(buff); } catch (IOException ex) { Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex); } try { IoS.close(); } catch (IOException ex) { Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) {Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex);} }}); sav.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ev){ try{DataOutputStream IsS = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fn+".txt")));//Здесь ошибка (fn) String fil=ta.getText(); byte[] buf=fil.getBytes(); try { IsS.write(buf); } catch (IOException ex) { Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex); } try { IsS.close(); } catch (IOException ex) { Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) {Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex);}}}); } }