Resources are not real File
s on the file system, but on the class path. They could be packed in a jar with an URL like "jar:file://.../xyz.jar!test.csv"
. Hence use an InputStream.
InputStream in = getClass().getResourceAsStream("/test.csv");
String userHome = System.getProperty("user.home");
Path path = Paths.get(userHome, "test2.csv");
Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
Resources should be considered read-only; hence use them as template, initial empty file, read-only data or such.
The ClassLoader has only absolute paths under the root src/main/resources, without starting /
. The Class has URLs relative to the class' package directory (but under src/main/resources), or starting with /
an absolute path.