Use JFileChooser open txt file displayed in the label hill

在这里插入代码片
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();
}
}
}

Published 130 original articles · won praise 16 · views 30000 +

Guess you like

Origin blog.csdn.net/feiqipengcheng/article/details/105127057