2013-04-05 60 views
0

移动文件到目前为止,这是我的代码我想选择的文件移动到一个路径,我将在后面的代码定义了我如何从selcted文件获取路径在Java

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); 
    } 
} 

回答

1

你可以通过这种方式获得所选文件:

if (returnVal == JFileChooser.APPROVE_OPTION) { 
    File file = fc.getSelectedFile(); 
    ... 
} else { 
    // this means that the user closed the dialog or pressed Cancel 
} 
1

大多数swing组件在官方网站上都有很好的教程。 JFileChooser的教程是here

它基本上归结为;

if (returnVal == JFileChooser.APPROVE_OPTION) { 
    File file = fc.getSelectedFile().getPath(); 
    ..... 
} 
+0

感谢您的答案,但我该如何将文件从位置a移动到位置b(a将是〜/ Downloads/FILE和b将是〜/ Library/Application Support \ Minecraft/bin/minecraft.jar – user2248741 2013-04-08 16:58:36