Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么不在指定位置创建备份文件?_Java_Mysql - Fatal编程技术网

Java 为什么不在指定位置创建备份文件?

Java 为什么不在指定位置创建备份文件?,java,mysql,Java,Mysql,执行此代码时,不会创建重定向中指定的文件。为什么不呢 public class MyDdlSql { public static void main(String[] args) { try { Runtime.getRuntime().exec("mysqldump -uroot -psuri biztime >D:data.sql"); } catch (IOException e) { e.pri

执行此代码时,不会创建重定向中指定的文件。为什么不呢

public class MyDdlSql {
    public static void main(String[] args) {
        try {
            Runtime.getRuntime().exec("mysqldump -uroot -psuri biztime >D:data.sql");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
看这里:

重定向是shell的一个功能。所以你不能用它。相反,您应该使用ProcessBuilder

ProcessBuilder builder = new ProcessBuilder("mysqldump", "-uroot", "-psuri", "biztime");
builder.redirectOutput(new File("D:\\data.sql"));
builder.redirectError(new File("error.log"));
Process p = builder.start();

看起来你正在使用windows。您正在使用相对路径。因此,您必须查看当前目录(在驱动器D下)或使用绝对路径,如D:\\data.sql(您必须引用反斜杠,也可以使用正斜杠)。此外,您还需要使用管理权限运行程序,但该权限也不起作用。。。。。。文件未创建打包计划程序;导入java.io.IOException;公共类MyDdlSql{public static void main(String[]args){try{Process p=Runtime.getRuntime().exec(“mysqldump-uroot-psuri biztime>D:\\data22.sql”);int i=p.waitFor();if(i==0){System.out.println(“success”)}else{System.out.println(“fail”);}catch(IOException | InterruptedException e){e.printStackTrace();}}}}}这给出了失败和未在指定位置创建的文件……….包调度程序;导入java.io.IOException;公共类MyDdlSql{public static void main(String[]args){try{Process p=Runtime.getRuntime().exec(“mysqldump-uroot-psuri biztime>D:\\data22.sql”);int i=p.waitFor();如果(i==0){System.out.println(“成功”);}else{System.out.println(“失败”);}}}catch(IOException | InterruptedException e){e.printStackTrace();}}}这给出了失败和未在指定位置创建的文件。。。。。。。。。。