當前位置:首頁 » 編程語言 » java選擇文件

java選擇文件

發布時間: 2025-03-16 04:29:20

java中jfilechooser有沒有可以選擇文件夾

private JFileChooser fc=new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//只能選擇目錄
String path=null;
File f=null;
try{
flag=fc.showOpenDialog(null);
}
catch(HeadlessException head){
System.out.println("Open File Dialog ERROR!");
}
if(flag==JFileChooser.APPROVE_OPTION){
//獲得該文件
f=fc.getSelectedFile();
path=f.getPath();
}

//以上獲得選擇的文件夾
//若要判斷其中是否還有其他目錄,可以這樣做
boolean hasSubDir=false;
File dir=new File(path);
//獲得改目錄下的文件的文件名,如果沒有的話,filesName.length()=0
String filesName=dir.list();
for(int i=0;i<filesName.length();i++){
File temp=new File(path+"/"+filesName[i]);
if(temp.isDirectory()){
hasSubDir=true;
break;
}

}

② Java如何做出好看的本地文件選擇器

更改一下外觀為windows的:
if(UIManager.getLookAndFeel().isSupportedLookAndFeel()){
final String platform = UIManager.getSystemLookAndFeelClassName();
// If the current Look & Feel does not match the platform Look & Feel,
// change it so it does.
if (!UIManager.getLookAndFeel().getName().equals(platform)) {
try {
UIManager.setLookAndFeel(platform);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}

如果不需要文件過濾可以選擇 FileDialog來打開仔衡文件,這個是調用操作系統的文件筐野肆打開文件的,但是在window下實現不了文件過濾,其他系統下可以。如果念脊做用JFileChoose可以很容易實現,文件過濾,但是界面默認是java外觀。如果要好看,可以設置一下顯示外觀。

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:639
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:368
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:84
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:310
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:793
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:344
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:212
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:812
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:366
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:592