首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileCopyUtils Springframework框架

FileCopyUtils Springframework框架
EN

Stack Overflow用户
提问于 2015-02-02 15:43:50
回答 2查看 5.1K关注 0票数 0

我想使用spring FileCopyUtils复制一个文件。这是我第一次使用教程,我得到了这个异常

代码语言:javascript
复制
package com.sctrcd.multidsdemo.integration.repositories.foo;

import java.io.File;
import java.io.IOException;

import org.springframework.util.FileCopyUtils;

public class CopyTest {

    public static void main(String[] args) throws InterruptedException,
            IOException {

        File source = new File("‪C:\\Users\\Momo Kh\\Desktop\\CV.pdf");
        File dest = new File("C:\\Users\\Momo Kh\\Desktop\\Test\\CV.pdf");
        FileCopyUtils.copy(source, dest);

    }

}

我有个例外

代码语言:javascript
复制
Exception in thread "main" java.io.FileNotFoundException: ‪C:\Users\Momo Kh\Desktop\CV.pdf (La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:63)
    at com.sctrcd.multidsdemo.integration.repositories.foo.CopyTest.main(CopyTest.java:15)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-04 09:19:54

这段代码的工作原理(与上次的修改相同),我认为这是个bug。

代码语言:javascript
复制
package com.sctrcd.multidsdemo.integration.repositories.foo;

import java.io.File;
import java.io.IOException;

import org.springframework.util.FileCopyUtils;

public class CopyTest {

    public static void main(String[] args) throws InterruptedException,
            IOException {

        File source = new File("C:\\Users\\Momo Kh\\Desktop\\CV.pdf");
        File dest = new File("C:\\Users\\Momo Kh\\Desktop\\files\\destfile1.pdf");


        long start = System.nanoTime();
        long end;

        // copy file using Spring FileCopyUtils
        start = System.nanoTime();
        FileCopyUtils.copy(source, dest);
        end = System.nanoTime();
        System.out.println("Time taken by Spring FileCopyUtils Copy = " + (end - start));



    }

}

和结果

代码语言:javascript
复制
Time taken by Spring FileCopyUtils Copy = 41100377
票数 -1
EN

Stack Overflow用户

发布于 2015-02-02 16:10:14

要么你没有文件,要么你没有必要的隐私去触摸它。尝试一些像C:\\Momo Kh\\CV.pdf这样的目录。也许你不能访问用户下的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28281360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档