Log in
updated 11:29 AM UTC, May 4, 2016

Copy Files from Classpath to another temp location in Java

  • Written by Madhu V Rao
  • Published in Core Java

Here is a snippet to copy a file (just the file name) which is in the classpath to another location

Using all the utility methods provided by java to do so.

 

private void copyReadMeFile
                (String tempFilesOutputPath2, String readmeFile) 
                                              throws IOException {
		
    Path inputPath = Paths.get(this.getClass().getClassLoader().
                              getResource(readmeFile).getPath());
    Path path = Paths.get(tempFilesOutputPath2 + File.separator + readmeFile);
    try {
         Files.copy(inputPath, path, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
         throw e;
    }
}

Powered by Bullraider.com
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest