【发布时间】:2015-11-23 19:37:48
【问题描述】:
执行此代码时,不会创建重定向中指定的文件。为什么不呢?
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();
}
}
}
【问题讨论】:
-
看起来您正在使用 Windows。您正在使用相对路径。所以你必须查看你的当前目录(在驱动器 D 下)或使用像 D:\\data.sql 这样的绝对路径(你必须引用反斜杠,或者你可以使用正斜杠)。
-
另外你需要以管理员权限运行程序
-
这也不起作用......文件未创建
-
包调度器;导入 java.io.IOException; public class 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("成功"); } else{ System.out.println("失败"); } } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } 这给出了失败和文件未在指定位置创建............