String dumpCommand = "C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump" + " -u " + user + " -p" + " " + database + " > " + path;
Runtime rt = Runtime.getRuntime();
File test = new File(path);
PrintStream ps;
try{
Process child = rt.exec(dumpCommand);
System.out.println("Child" + child);
ps = new PrintStream(test);
InputStream in = child.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
ps.write(ch);
System.out.write(ch);
}
}
該代碼無法正常工作。它無限運行?我如何在java上運行mysqldump?代碼不工作,它無限運行?
不要使用'Runtime.exec()',使用'ProcessBuilder' – fge
如何在D:驅動器中使用ProcessBuilder()作爲mysqldump的command.Project位置。 Mysqldump的位置是C:\ ProgramFiles \ MySQL \ MySQLServer5.0 \ bin \ mysqldump \ – Ajithlal
這是Java 7還是Java 6?回答取決於使用java 6的 – fge