怎样编写这样的程序?
从键盘上输入一个文本文件的名字,在屏幕上显示这个文件的内容?
不知道怎么下手?
那位写个程序出来,参考参考!!!谢谢!!!

解决方案 »

  1.   

    java中的输入输出流可以实现
    限于时间关系就步写了
      

  2.   

    import java.io.*;public class TestFile {
        public static void main(String[] args){
            BufferedInputStream in=new BufferedInputStream(System.in);
            String fn=null;
            String buf=null;
            int fnlen=0;
            byte[] b=new byte[256];
            try{
                if((fnlen=in.read(b, 0, b.length))>0){
                    fn=new String(b,0,fnlen-1,"UTF-8");
                    BufferedReader br=new BufferedReader(new FileReader(fn));
                    while((buf=br.readLine())!=null)
                        System.out.println(buf);
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }      
    }
      

  3.   

    用按钮怎么实现?
    就是说在上面增加几个按钮:一个按钮,一个文本域,一个文本区,
    在Jbulider里实现?
    那该怎么实现?
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
     class MenuTest
    {
    public static void main(String args[])
    {
    final Frame f=new Frame("http://www.zhiyuan.com");
    f.setSize(500,400);
    f.setLocation(256,200);
    f.setBackground(Color.LIGHT_GRAY);
    f.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }});
    final TextArea  ta=new TextArea();
         ta.disable();
    f.add(ta);
    MenuBar mb=new MenuBar();
    Menu m1=new Menu("File");
    Menu m2=new Menu("Edit");
    MenuItem mi1=new MenuItem("New");
    MenuItem mi2=new MenuItem("Open");
    MenuItem mi3=new MenuItem("Save");
    MenuItem mi4=new MenuItem("Exit");
    MenuItem mi5=new MenuItem("Paste");
    MenuItem mi6=new MenuItem("Delete");
    mi4.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)

    {
    System.exit(0);
    }
    });
    mi2.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    FileDialog fd=new FileDialog(f,"OPenning The File",FileDialog.LOAD);
    fd.show();
    String strFile=fd.getDirectory()+fd.getFile();
    ta.setText("");
    if(strFile!=null)
    try 
    {
    ta.enable();
              FileInputStream fis=new FileInputStream(strFile);
              byte[] b=new byte[20*1024];
              int len=fis.read(b);
              ta.append(new String(b,0,len));
              fis.close();
              
    }
    catch(Exception ex)
    {
    System.out.println(ex.toString());
    }

    }
    });
    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();
    }
    }