简体   繁体   English

需要在Windows中使用wget复制文件

[英]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.

相关问题 使用Putty-Windows中的SSH将ubuntu中的文件复制到Windows - Copy a file in ubuntu to windows using putty - ssh from windows 在Windows机器上使用Java Code将本地文件复制到Unix Server? - Copy local file to Unix Server using java Code on windows machine? 如何在Java中使用User / Pass将文件复制到另一个Windows PC - How to copy a file to another windows pc using user/pass in java 使用 java.nio.file.Files.copy() 将文件从 Linux 复制到 Windows 远程机器 - Copy a file to a Windows remote machine from Linux using java.nio.file.Files.copy() 将文件从Android复制到Windows - Copy file from Android to Windows 使用wget和Nexus Rest API命名奇数文件 - Odd file naming using wget with Nexus Rest API 如何使用与wget集成的Selenium WebDriver(Java)下载文件 - How to download a file using Selenium WebDriver (Java) integrated with wget 使用Java将文件从Windows计算机复制到Linux计算机的最佳方法 - Best way to copy a file from Windows machine to Linux machine using java 如何使用java(在Windows上)从一个路径到另一路径制作任何文件(任何扩展名)的副本? - how to make of a copy of any file(any extension) from one path to another using java(on windows)? 如何使用Java从Windows计算机向服务器发送文件(移动/复制) - How to send a file (move/copy) from windows computer to server using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM