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

熱點內容
視頻伺服器搭建海康 發布:2025-04-30 23:50:29 瀏覽:95
xp共享怎麼設置密碼 發布:2025-04-30 23:50:24 瀏覽:160
租用電腦主機搭建伺服器 發布:2025-04-30 23:28:06 瀏覽:733
php子類調用父類方法 發布:2025-04-30 23:11:55 瀏覽:678
存檔加密id 發布:2025-04-30 22:20:50 瀏覽:748
mac搭建php環境 發布:2025-04-30 21:58:13 瀏覽:141
雅迪電動車配置有哪些 發布:2025-04-30 21:38:27 瀏覽:162
為什麼用文件存儲取代mysql 發布:2025-04-30 21:17:26 瀏覽:614
我的世界免費伺服器ip 發布:2025-04-30 20:41:26 瀏覽:775
華為雲相冊在哪裡找安卓11 發布:2025-04-30 20:19:59 瀏覽:274