import java.awt.*;
import java.awt.event.*;
import java.awt.Color.*;
import java.io.*;
class File extends Frame implements FocusListener,ActionListener
{
TextArea ta=new TextArea("",10,30);
TextField tf=new TextField(30);
Button b=new Button("读取数据");
File()
{
this.add(ta,"North");
this.add(tf,"Center");
this.add(b,"South");
tf.addFocusListener(this);
tf.setText("在此输入文件路径…");
tf.setForeground(Color.gray);
b.addActionListener(this);
this.pack();
this.setVisible(true);
}
public void focusGained(FocusEvent e)
{
if(e.getSource()==tf)
{
tf.setText("");
tf.setForeground(Color.black);
}
}
public void focusLost(FocusEvent e){}
File f;
FileInputStream fi;
BufferedReader br;
public void actionPerformed(ActionEvent e)
{
f=new File(tf.getText());
fi=new FileInputStream(f);
br=new BufferedReader(new InputStreamReader(fi));
String strText=null;
while((strText=br.readLine())!=null)
{
strText=strText+"\n";
}
ta.setText(strText);
}
public static void main(String[] args)
{
new File();
}
}
把你的类名改成FileFrame或者其它非File的类名,并修改构造函数名就好了
你这个类名叫File和Java.io包里的Java.io.File冲突啊,所以先改个名字再看
报的什么错误你贴出来看看吧