打开文件的功能代码 JFileChooser

//最近很迷茫,什么都没有学到,也感觉很疲惫。找到一个很好的GUI控件,跟大家分享一下

import javax.swing.JFileChooser;

public class yydm {
public static void main(String args[]){

JFileChooser jFileChooser = new JFileChooser();
int i = jFileChooser.showOpenDialog(null);
//打开文件:其中0表示打开,1表示没打开,好像跟Boolean型是相反的.
if(i== jFileChooser.APPROVE_OPTION){
String path = jFileChooser.getSelectedFile().getAbsolutePath();
String name = jFileChooser.getSelectedFile().getName();
System.out.println("当前文件路径:"+path+"; 当前文件名:"+name);
}else{
System.out.println("没有选中文件");
}
}

}

原文地址:https://www.cnblogs.com/qiqisx/p/7648722.html