[英]Need to copy a file using wget in windows
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();
}
}
Hi all, 大家好,
I want to copy a file from URL to my folder(src). 我想将文件从URL复制到我的文件夹(src)。 I tried through java, i got error illegal escape character.
我尝试通过Java,但出现错误非法转义字符。 but the above wget works in command prompt.
但是上面的wget在命令提示符下工作。 Please help me..Thanks in advance.
请帮助我。。谢谢。
那么“ \\”应该在Java字符串中转义为“ \\\\”。
C:\vignesh\Docx\docx_final\Html2Docx\src
->
C:\\vignesh\\Docx\\docx_final\\Html2Docx\\src
To get the code to compile you need to escape the '\\' characters in your call to Runtime.getRuntime().exec()
. 为了使代码得以编译,您需要在对
Runtime.getRuntime().exec()
调用中转义“ \\”字符。
The second problem you will have is that your call to p.destroy()
is terminating the process before it has completed. 您将遇到的第二个问题是对
p.destroy()
调用将在该过程完成之前终止该过程。 You can either delete the call or, if you wish to do further processing once the download has completed, call p.waitFor()
. 您可以删除该调用,或者,如果您希望在下载完成后做进一步处理,请调用
p.waitFor()
。
Your code would then look like this: 您的代码将如下所示:
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.