📄 filereadertest.java
字号:
import java.applet.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class FileReaderWindow extends Frame implements ActionListener
{
TextArea text;
BufferedReader in;
Button button;
FileReader file;
FileReaderWindow()
{
super("流的读取");
text=new TextArea(10,10);
text.setBackground(Color.cyan);
try
{
File f=new File("E:\\信息系统开发技术\\", "Testfile.txt");
file=new FileReader(f);
in=new BufferedReader(file);
}
catch(FileNotFoundException e)
{}
catch(IOException e)
{}
button =new Button("读取");
button.addActionListener(this);
setLayout(new BorderLayout());
setSize(40, 40);
setVisible(true);
add(text, "Center");add("South", button);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
String s;
if(e.getSource()==button)
try
{
while((s=in.readLine())!=null)
text.append(s+'\n');
}
catch(IOException exp)
{}
}
}
public class FileReaderTest
{
public static void main(String args[])
{
FileReaderWindow w=new FileReaderWindow();
w.pack();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -