在这里插入代码片
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.*;
public class a extends JApplet{
public a() {
JFileChooser a1=new JFileChooser(new File("."));
a1.showOpenDialog(this);
try {
BufferedInputStream in=new BufferedInputStream(new FileInputStream(a1.getSelectedFile()));
JLabel b1=new JLabel();
byte[]b=new byte[in.available()];
in.read(b,0,b.length);
b1.setText(new String(b,0,b.length));
add(b1);
in.close();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
使用JFileChooser打开txt文件显示在标签山上
最新推荐文章于 2022-05-29 20:25:42 发布