import java.io.*;
class demo
{
public static void main(String str[]) throws Exception
{
Process p = Runtime.getRuntime().exec("wget -P C:\vignesh\Docx\docx_final\Html2Docx\src http://anbu/upload/ExportHtml.html");
p.destroy();
}
}
大家好
我想将文件从 URL 复制到我的文件夹 (src)。我尝试通过 java,我得到了错误的非法转义字符。但上面的 wget 在命令提示符下工作。请帮助我..提前致谢。
最佳答案
要编译代码,您需要在对 Runtime.getRuntime().exec()
的调用中转义“\”字符。
您将遇到的第二个问题是您对 p.destroy()
的调用在进程完成之前终止了该进程。您可以删除调用,或者如果您希望在下载完成后进行进一步处理,请调用 p.waitFor()
。
您的代码将如下所示:
class demo {
public static void main( String str[] ) throws Exception {
Process p = Runtime.getRuntime().exec( "wget -P C:\\vignesh\\Docx\\docx_final\\Html2Docx\\src http://anbu/upload/ExportHtml.html"" );
p.waitFor();
// do more processing
}
}
关于java - 需要在 Windows 中使用 wget 复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5026027/