package Test;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextPane;
public class demo extends JFrame {
public static void main(String[] args) {
demo jf=new demo();
jf.setSize(500,500);
jf.setLayout(null);
JButton input=new JButton("点击导入文本");
input.setBounds(0,0,150,50);
jf.add(input);
JTextPane jtp=new JTextPane();
jtp.setBounds(60,80,350,350);
jf.add(jtp);
jf.setVisible(true);
input.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JFileChooser fd = new JFileChooser();
fd.setFileSelectionMode(JFileChooser.OPEN_DIALOG);
fd.showOpenDialog(null);
File f = fd.getSelectedFile();
if (f !=
Java swing打开文件目录读出、导入txt文件的一种方法
最新推荐文章于 2021-08-30 15:01:36 发布
本文介绍如何使用Java Swing库打开文件目录,并详细讲解读取及导入TXT文本文件的步骤,适合Java初学者和需要处理文本数据的开发者。
摘要由CSDN通过智能技术生成