2017-03-03 105 views
-1

我想將包含其他類型文件的文件夾中的所有.mp3文件複製到另一個音樂文件夾中。我寫了一段代碼,但它不起作用。這個怎麼做。使用java將.mp3文件從一個文件夾複製到另一個文件夾

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); 
    } 
} 
+5

可能重複的[如何將文件從一個位置複製到另一個位置?](http://stackoverflow.com/questions/16433915/how-to-copy-file-from-one-location-to -otherother-location) – DimaSan

+0

提示:獲取mp3文件的列表(查看File.listFiles(),然後逐個複製它們,但不能按照您嘗試的方式批量執行它們) –

+0

並使用FilenameUtils來檢查它是否是您想要複製或跳過的擴展 – Zeromus

回答

0

您可以使用。

Files.copy(src, dest, REPLACE_EXISTING); 
相關問題