readfiletestindir.java

来自「java练习程序」· Java 代码 · 共 37 行

JAVA
37
字号
import java.io.*;
import java.awt.*;
import java.awt.event.*;

class ReadFileTestInDir {
    static Frame f;
    public static void main(String args[]) {
        int b, j = 10;
        TextArea text;
        byte tom[] = new byte[2500];
        f = new Frame();
        f.setSize(100, 100);
        text = new TextArea(30, 60);
        f.setVisible(true);
        f.add(text);
        f.pack();
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                f.setVisible(false);
                System.exit(0);
            }
        });
        try {
            File f = new File("E:\\信息系统开发技术\\", "Testfile.txt");
            FileInputStream readfile = new FileInputStream(f);
            while ((b = readfile.read(tom, 0, j)) != -1) {
                String s = new String(tom, 0, j);
                System.out.println(s);
                text.append(s + '\n');
            }
            readfile.close();
        } catch (IOException e) {
            System.out.println("Pile read Error ");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?