我交替应用注释 1 和 2。但我没有使用在 cmd 中工作的 java.mysqldump 获得 myqldump 文件。我认为在 cmd 中输入 mysqldump 评论后会询问密码。请帮助我fast.thanks提前。
String dumpCommand = "C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump" + " -u " + user + " -p" + " " + database + " > " + path;
**//command 1**
Runtime rt = Runtime.getRuntime();
File test = new File(path);
PrintStream ps;
try {
// Process child = rt.exec("Cmd /c \"C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump\" -u root -p saxco > "+path);//command 2
Process child = rt.exec(dumpCommand);
ps = new PrintStream(test);
InputStream in = child.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
ps.write(ch);
System.out.write(ch);
}