کلیدستان

نسخه‌ی کامل: کپی فایل از پوشه assets به حافظه خارجی
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
ببخشید میشه بگید چطوری فایلی رو از پوشه assets به حافظه خارجی کپی کنیم.؟


کد زیر درست هستش؟
نام فایلمو کجای کد باید بنویسم؟


کد پی‌اچ‌پی:
private void copyAssets() {
        
AssetManager assetManager getAssets();
        
String[] files null;
        try {
            
files assetManager.list("");
        } catch (
IOException e) {
            
Log.e("tag""Failed to get asset file list."e);
        }
        for(
String filename files) {
            
InputStream in null;
            
OutputStream out null;
            try {
              
in assetManager.open(filename);
              
File outFile = new File(getExternalFilesDir(null), filename);
              
out = new FileOutputStream(outFile);
              
copyFile(inout);
            } catch(
IOException e) {
                
Log.e("tag""Failed to copy asset file: " filenamee);
            }     
            finally {
                if (
in != null) {
                    try {
                        
in.close();
                    } catch (
IOException e) {
                        
// NOOP
                    
}
                }
                if (
out != null) {
                    try {
                        
out.close();
                    } catch (
IOException e) {
                        
// NOOP
                    
}
                }
            }  
        }
    }
    private 
void copyFile(InputStream inOutputStream outthrows IOException {
        
byte[] buffer = new byte[1024];
        
int read;
        while((
read in.read(buffer)) != -1){
          
out.write(buffer0read);
        }
    } 
 
سلام
به کلید زیر بروید همین موضوعی که گفتین به طور کامل شرح داده شده است.
کلید848