0

I want to copy all .mp3 files from a folder which contains other types of files too,to another music folder.I have written a code but it does not work.How to do this.

 public static void main(String[] args) {
    File src=new File("C:\\Users\\RakeshS\\Downloads\\.mp3");
    File dest=new File("C:\\Users\\RakeshS\\Music");
    String content="C:\\Users\\RakeshS\\Downloads\\.mp3";
    try{
           Files.write(Paths.get("C:\\Users\\RakeshS\\Music"), content.getBytes(), StandardOpenOption.CREATE);
    }catch(IOException e)
    {
        System.out.println(e);
    }
}
aeshna
  • 83
  • 1
  • 2
  • 9
  • 5
    Possible duplicate of [How to copy file from one location to another location?](http://stackoverflow.com/questions/16433915/how-to-copy-file-from-one-location-to-another-location) – DimaSan Mar 03 '17 at 14:54
  • Hint: get a list of the mp3 files (look at File.listFiles(), then copy them one by one. You can't do them in bulk the way you're trying to do it. – Brian Pipa Mar 03 '17 at 14:58
  • and use FilenameUtils to check if it is the extension you want to copy or skip it – Zeromus Mar 03 '17 at 15:00
  • [Files.copy(Path source, Path target, CopyOption...options)](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#copy-java.nio.file.Path-java.nio.file.Path-java.nio.file.CopyOption...-) – Fildor Mar 03 '17 at 15:09

1 Answers1

0

You can do that using.

Files.copy(src, dest, REPLACE_EXISTING);
Ravi MCA
  • 2,491
  • 4
  • 20
  • 30