简体   繁体   English

使用Java IO将文件从本地复制到远程系统

[英]File Copy from local to remote system using java IO

I need to copy a file from my local system to remote system, for this I'm using the following code: 我需要将文件从本地系统复制到远程系统,为此,我使用以下代码:

    public class Autohost {

    public static void main(String[] args) throws IOException {
        InputStream in = new FileInputStream(new File(
                "C:\\Users\\Jainesh_Trivedi\\Desktop\\WAR\\AutohostDemo1_1145.war"));

        File f = new File("10.87.74.191\\C$\\IVS_Code\\tomcat\\apache-tomcat-7.0.57\\webapps\\AutohostDemo1_1145.war");
        f.createNewFile();
        OutputStream out = new FileOutputStream(f);
        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;

        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);



        }
        in.close();
        out.close();


    }
}

But I'm getting the following error: 但我收到以下错误:

        Exception in thread "main" java.io.IOException: The system cannot find the path specified
        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
        at java.io.File.createNewFile(Unknown Source)
        at com.autohost2.java.Autohost.main(Autohost.java:18)

The filename on this line 这行的文件名

File f = new File("10.87.74.191\\C$\\IVS_Code\\tomcat\\apache-tomcat-7.0.57\\webapps\\AutohostDemo1_1145.war");

is not a valid UNC path. 不是有效的UNC路径。 You need two backslashes (four, in code) to signal a remote path. 您需要两个反斜杠(在代码中为四个)来指示远程路径。 Fixed version: 固定版本:

File f = new File("\\\\10.87.74.191\\C$\\IVS_Code\\tomcat\\apache-tomcat-7.0.57\\webapps\\AutohostDemo1_1145.war");

Also make sure that security settings on the remote machine are configured to allow your account the appropriate access. 还要确保将远程计算机上的安全设置配置为允许您的帐户进行适当的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java将文件从本地文件夹复制到远程文件夹 - Copy file from local folder to remote folder using java 将文件从HDFS复制到本地系统而不使用sudo - copy a file from HDFS to local system without using sudo 如何使用java从远程系统读取文件? - How to read a file from remote system using java? 使用Java中的多线程将大量文件从本地复制到DBFS服务器 - bulk of file copy from local to DBFS server using multithreading in java 是否可以运行HADOOP并将文件从本地fs复制到JAVA BUT中的HDFS,而无需在文件系统上安装Hadoop? - Is that possible to run HADOOP and copy a file from local fs to HDFS in JAVA BUT without installing Hadoop on file system? 使用 java.nio.file.Files.copy() 将文件从 Linux 复制到 Windows 远程机器 - Copy a file to a Windows remote machine from Linux using java.nio.file.Files.copy() 使用Java发送邮件:文件未从本地系统附加 - Sending mail using java : file is not getting attached from local system 有没有办法使用 java 从本地系统上传文件到 EFS? - Is there a way to upload file to EFS from local system using java? 使用Java将文件从SFTP服务器传输到本地系统 - Transfer file from SFTP server to the local system using Java 使用Java将文件从本地窗口机器复制到远程Windows机器 - Copy files from local window machine to remote windows machine using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM