我想使用spring FileCopyUtils复制一个文件。这是我第一次使用教程,我得到了这个异常
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);
}
}我有个例外
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)发布于 2015-02-04 09:19:54
这段代码的工作原理(与上次的修改相同),我认为这是个bug。
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));
}
}和结果
Time taken by Spring FileCopyUtils Copy = 41100377发布于 2015-02-02 16:10:14
要么你没有文件,要么你没有必要的隐私去触摸它。尝试一些像C:\\Momo Kh\\CV.pdf这样的目录。也许你不能访问用户下的东西。
https://stackoverflow.com/questions/28281360
复制相似问题