将文件从a移动到b

时间:2013-04-10 16:36:42

标签: java file installer

这是我的实际移动代码:

    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

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

1 个答案:

答案 0 :(得分:0)

google上关于“java移动文件”的第一个解决方案:how to move/copy a file in java
希望这会有所帮助:)