0

到目前为止,这是我的代码,我想将选定的文件移动到我稍后将在代码中定义的路径我如何从选定的文件中获取路径

import java.awt.Component;
import javax.swing.JFileChooser;



public class CopyFileExample 
{
    public static void main(String[] args)
    {   

        final JFileChooser fc = new JFileChooser();
        Component aComponent = null;
        int returnVal = fc.showOpenDialog(aComponent);
    }
}
4

2 回答 2

1

您可以通过以下方式获取所选文件:

if (returnVal == JFileChooser.APPROVE_OPTION) {
  File file = fc.getSelectedFile();
  ...
} else {
  // this means that the user closed the dialog or pressed Cancel
}
于 2013-04-05T11:07:15.883 回答
1

大多数swing组件在官方网站上都有非常好的教程。教程JFileChooser这里

它基本上归结为;

if (returnVal == JFileChooser.APPROVE_OPTION) {
  File file = fc.getSelectedFile().getPath();
  .....
}
于 2013-04-05T11:09:22.353 回答