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

熱點內容
cod17編譯著色器55 發布:2025-07-08 15:43:53 瀏覽:558
Shell腳本的posix模式 發布:2025-07-08 15:41:32 瀏覽:352
壓縮奶油消泡 發布:2025-07-08 15:40:11 瀏覽:425
伺服器一定要有公網ip嗎 發布:2025-07-08 15:35:12 瀏覽:797
appendpython 發布:2025-07-08 15:22:54 瀏覽:656
安卓虛擬號碼怎麼設置 發布:2025-07-08 15:22:04 瀏覽:663
c語言愛心代碼編譯不出來 發布:2025-07-08 15:11:07 瀏覽:540
qq密碼的資料庫 發布:2025-07-08 14:54:50 瀏覽:6
多圖床源碼 發布:2025-07-08 14:46:36 瀏覽:573
sqldblinkoracle 發布:2025-07-08 14:44:50 瀏覽:608