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 fro开发者_JAVA技巧m URL to my folder(src). I tried through java, i got error illegal escape character. but the above wget works in command prompt. Please help me..Thanks in advance.
To get the code to compile you need to escape the '\' characters in your call to Runtime.getRuntime().exec()
.
The second problem you will have is that your call to p.destroy()
is terminating the process before it has completed. You can either delete the call or, if you wish to do further processing once the download has completed, call 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
}
}
Well "\" should be escaped to "\\" in Java strings.
C:\vignesh\Docx\docx_final\Html2Docx\src
->
C:\\vignesh\\Docx\\docx_final\\Html2Docx\\src
精彩评论