1. 程式人生 > >打開文件的功能代碼 JFileChooser

打開文件的功能代碼 JFileChooser

ava sta str style height 沒有 line public dial

//最近很迷茫,什麽都沒有學到,也感覺很疲憊。找到一個很好的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+";\n當前文件名:"+name);
}else{
System.out.println("沒有選中文件");
}
}

}

打開文件的功能代碼 JFileChooser