日期:2014-05-20  浏览次数:20698 次

如果实现打开文件夹或一个文件
选择想要打开的文件夹(或文件),并记录该文件夹(或文件)所对应的路径.如果写这个代码呢?

------解决方案--------------------
JFileChooser
------解决方案--------------------
JFileChooser 可以选择文件夹的。楼主去看下 JFileChooser的API吧

很清晰
------解决方案--------------------
JFileChooser
------解决方案--------------------
JFileChooser
public class JFileChooserextends JComponentimplements AccessibleJFileChooser provides a simple mechanism for the user to choose a file. For information about using JFileChooser, see How to Use File Choosers, a section in The Java Tutorial.

The following code pops up a file chooser for the user 's home directory that sees only .jpg and .gif images:

JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images ", "jpg ", "gif ");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println( "You chose to open this file: " +
chooser.getSelectedFile().getName());
}