當前位置:首頁 » 編程語言 » 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外觀。如果要好看,可以設置一下顯示外觀。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:646
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:937
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:633
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:822
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:732
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1067
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:300
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:161
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:853
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:764