I want to copy a file using spring FileCopyUtils. this is the first time I used I followed a tutorial and I get this exception
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); }
}And i have this Exception
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) 0 2 Answers
Either you don't have the file or you don't have the necessary priviliges to touch it. Try some directory like C:\\Momo Kh\\CV.pdf instead. Maybe you can't access stuff under user.
This code works (The same as the last with some change) I think it was a 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)); }
}And the result
Time taken by Spring FileCopyUtils Copy = 41100377