2011-11-16 112 views
0

我需要找到一種方法來創建從我的設備的內部存儲中的特定文件夾到外部存儲中特定文件夾的文件。Android如何將文件夾從內部存儲器複製到外部

實施例:

  • 我在內部存儲在data/data/app_package/files/documents/server/userId/storage/ 50的圖像文件。
  • 我想在該目錄中的所有文件複製到/sdcard/Documents/Server/UserId/Storage/

這個想法是,在某些情況下,也許我將不得不像移動和50MB的文件也許更多。任何建議我怎麼能做到這一點?

回答

2

試試這個代碼

private void copyToFolder(String path) throws IOException { 
    File selectedImage = new File(path); 
    if (selectedImage.exists()) { 
     String wall = selectedImage.getName(); 

     in = getContentResolver().openInputStream(selectedImageUri); 
     out = new FileOutputStream("/sdcard/wallpapers/" + wall); 
     copyFile(in , out); in .close(); in = null; 
     out.flush(); 
     out.close(); 
     out = null; 
    } else { 
     System.out.println("Does not exist"); 
    } 
} 
private void copyFile(InputStream in , OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while ((read = in .read(buffer)) != -1) { 
     out.write(buffer, 0, read); 

    } 
} 
相關問題