使用JFileChooser获取目录中的所有文件名? [英] Get all file names in directory using JFileChooser?
本文介绍了使用JFileChooser获取目录中的所有文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
fileBrowser(){
String toReturn = null;
JFileChooser选择器=新的JFileChooser();
int choosen = Chooser.showOpenDialog(fileBrowser.this);
if(choosen == JFileChooser.APPROVE_OPTION){
System.out.println(Chooser.getCurrentDirectory()。toString()+\\+ Chooser.getSelectedFile()。getName() );
$ b code
$ b要获得所选的文件名和位置,这一切工作正常。我想知道作为一个补充,还有一种方法来获得该目录中的所有文件名?像 .getAllFiles()
之类的东西,我搜索了一遍,找不到一个?
提前。
解决方案 当然,请使用
File [] filesInDirectory = chooser.getCurrentDirectory()。listFiles();
然后你可以迭代这个数组:
< (File file:filesInDirectory){
System.out.println(file.getName()); pre>
}
I'm using this bit of code:
fileBrowser() {
String toReturn = null;
JFileChooser Chooser = new JFileChooser();
int choosen = Chooser.showOpenDialog(fileBrowser.this);
if (choosen == JFileChooser.APPROVE_OPTION) {
System.out.println(Chooser.getCurrentDirectory().toString()+"\\"+Chooser.getSelectedFile().getName());
}
}
To get the selected file name and location, which is all working fine. I was wondering as an addition, is there also a way to get all the filenames in that directory as well? something like .getAllFiles()
I've had a search around and can't find one?
Thanks in Advance.
解决方案 Sure, use
File[] filesInDirectory = chooser.getCurrentDirectory().listFiles();
Then you can iterate over that array:
for ( File file : filesInDirectory ) {
System.out.println(file.getName());
}
这篇关于使用JFileChooser获取目录中的所有文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文