-4

这是我的实际移动代码:

    import java.awt.Component;
    import java.io.File;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;

    public class CopyFileMac {

        public void COPY(){
            final JFileChooser fc = new JFileChooser();
            Component aComponent = null;
            int returnVal = fc.showOpenDialog(aComponent);

             if (returnVal == JFileChooser.APPROVE_OPTION) {
                  File file = fc.getSelectedFile();
                 } 
            else 
            {
                 JOptionPane.showMessageDialog(null, "You Selected Cancel");
                 System.exit(0);
            }
        }
    }

这是我的演示:

import javax.swing.*;
public class FileMover {

    /**
     * @param args
     */
     public static void main(String[] args) {
        CopyFilePc CopyFilePc = new CopyFilePc();
        CopyFileMac CopyFileMac = new CopyFileMac();
        String MacOrPc;

        MacOrPc = JOptionPane.showInputDialog(null, "Do you have a Mac or PC?");

        if (MacOrPc.equalsIgnoreCase("mac"))
         {
            CopyFileMac.COPY();
        }

        if (MacOrPc.equals("pc"))
        {
            CopyFilePc.COPY();
        }

我想移动 ~/Downloads/FILE

到 ~/Application support \ minecraft/bin/minecraft.jar (.jar 将被解压缩到一个文件夹中)

4

1 回答 1

0

谷歌关于“java move an file”的第一个解决方案:如何在java中移动/复制文件
希望这会有所帮助:)

于 2013-04-10T16:53:19.363 回答