سلام برای انتقال فایلی یا تصویر از پوشه ی assets میتونید از این کد استفاده کنید :
و برای فراخانی کد بالا از این کد میتونید برای نمونه استفاده کنید :
موفق باشی
کد:
public static void AssetFileCopy(Context context, String PathDest, String assetName, boolean gunzip) {
try {
File fdOut = new File(PathDest);
fdOut.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fdOut));
InputStream in = null;
if (gunzip)
in = new GZIPInputStream(context.getAssets().open(assetName));
else
in = new BufferedInputStream(context.getAssets().open(assetName));
//copy file content
int length;
byte buffer[] = new byte[4096];
while ((length = in.read(buffer, 0, 4096)) != -1) {
out.write(buffer,0,length);
}
out.flush();out.close();in.close();
} catch (IOException ex) { ex.printStackTrace(); }
}
و برای فراخانی کد بالا از این کد میتونید برای نمونه استفاده کنید :
کد:
AssetFileCopy(this, "/mnt/sdcard/image.jpg", "image.jpg", false);
// در اینجا image.jpg تصویر موجود در پوشه ی assets و "/mnt/sdcard/image.jpg" مسیر انتقال فایل میباشد .
موفق باشی