0

我制作了这段代码来移动一个文件夹,然后将它硬链接到它的原始目的地。当我只是从 Eclipse 中尝试它时,它完全可以工作,但是当我将它变成它自己的自我执行 jar 时,它不会创建硬链接,但它会移动文件夹。代码运行命令行,然后输入命令。我不知道移动命令有效,而另一个无效。请帮忙。(Mklink 命令)

import java.io.*;
import javax.swing.JOptionPane;

public class The_Cloud_Setup {
    public static void main(String[] args) throws IOException
    {
        try {
            String command = "c:\\cmd.exe";
            Runtime.getRuntime().exec(command);
        }
        catch (IOException e){
            JOptionPane.showMessageDialog(null , e.getMessage(), "End Result", 2);
            System.err.println(e.getMessage());
        }
        String[] StringMove = { "cmd.exe", "/c", "move"+" "+"\"C:/Users/%username%/Documents/My Games/Terraria/Players\""+" "+"\"C:/Users/%username%/Google Drive/Players\""};
        String[] StringMklink = {"cmd.exe", "/c",  "mklink"+" "+"/d"+" "+"\"C:/Users/%username%/Documents/My Games/Terraria/Players\""+" "+"\"C:/Users/%username%/Google Drive/Players\""};
        Process ProcessMove = Runtime.getRuntime().exec(StringMove);
        Process ProcessMklink = Runtime.getRuntime().exec(StringMklink);
        BufferedReader VarMove = new BufferedReader(new InputStreamReader(ProcessMove.getInputStream()));
         BufferedReader VarMklink = new BufferedReader(new InputStreamReader(ProcessMklink.getInputStream()));
        String temp = "";
        while ((temp = VarMove.readLine()) != null) {
            System.out.println(temp);
        }
        VarMove.close();
        VarMklink.close();
    }
}
4

1 回答 1

0

最有可能的是,当您在本机运行时,在您的程序尝试执行 mklink 命令之前 move 命令尚未完成。您无法在存在现有文件夹的位置创建链接。

于 2013-05-07T01:01:36.617 回答