源代码:
import java.awt.*;
import java.awt.event.*;
import java.io.*;public class HisFrame 
{
public static void main(String[] args)
{
final Frame f=new Frame("Makes You More Women");//起个名字
f.setSize(600,400);
f.setLocation(100,100);//设置窗口属性

final TextArea ta=new TextArea(); 
f.add(ta); //加入文本框


f.addWindowListener
(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);//加一个监听器,用来退出

//下面开始设置菜单

MenuBar mb=new MenuBar();

Menu m1=new Menu("set time");
Menu m2=new Menu("set voice");

MenuItem mi1=new MenuItem("New");

MenuItem mi2=new MenuItem("Open");//open有这些属性
mi2.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) 
{
FileDialog fd=new FileDialog(f,"Open The Dress You Like",FileDialog.LOAD);
fd.show();

String strFile=fd.getFile();
if (strFile!=null)
{
try 
{
FileInputStream fis=new FileInputStream(strFile);
byte[] buf=new byte[10*1024];
int len=fis.read(buf);
ta.append(new String(buf,0,len));


} catch (Exception e2) 
{
e2.printStackTrace();
}
}

}



});

MenuItem mi3=new MenuItem("Save");
MenuItem mi4=new MenuItem("Exit");

mi4.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);

});


MenuItem mi5=new MenuItem("Copy");
MenuItem mi6=new MenuItem("Paste");

m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi4);
m2.add(mi5);
m2.add(mi6);
mb.add(m1);
mb.add(m2);

f.setMenuBar(mb);
f.show(); 
}
 }
java.io.FileNotFoundException: 123.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at HisFrame$2.actionPerformed(HisFrame.java:50)
at java.awt.MenuItem.processActionEvent(MenuItem.java:627)
at java.awt.MenuItem.processEvent(MenuItem.java:586)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:300)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:288)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:602)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

解决方案 »

  1.   

    java.io.FileNotFoundException: 123.txt (The system cannot find the file specified)
    文件路径错了
      

  2.   

    java.io.FileNotFoundException   自己找个软件翻译一下    要学会自己看异常信息
      

  3.   


    String strFile=fd.getDirectory()+fd.getFile();文件路径错了
    调试一下就知道了 笨方法就是System.out.println(fd.getFile());
    多看看API