Копировать все данные из asset
Не подскажите, как копировать все папки, под папки и файлы из asset'ов на андроиде? Или это делается как и в обычной Java'е?
Источник: Stack Overflow на русском
Не подскажите, как копировать все папки, под папки и файлы из asset'ов на андроиде? Или это делается как и в обычной Java'е?
basePath - из которой, outPath - в которую.
private void copyAssets(String outPath, String basePath)
{
InputStream inputStream;
AssetManager assetManager = getAssets();
try {
String[] assets = assetManager.list(basePath);
for (String s: assets)
{
String[] tmp = assetManager.list(basePath+"/"+s);
if (tmp.length > 0)
{
File dir = new File(outPath + "/" + s);
dir.mkdir();
copyAssets(outPath + "/" + s, basePath + "/" + s);
continue;
}
byte[] inputBuffer = new byte[1000];
int count;
FileOutputStream f = new FileOutputStream(outPath + "/" + s);
inputStream = assetManager.open(basePath + "/" + s);
while ((count = inputStream.read(inputBuffer)) > 0)
f.write(inputBuffer, 0, count);
f.close();
}
}catch (Exception e) {
e.printStackTrace();
}
}