
我在assets文件夹中有几个文件.我需要将它们全部复制到文件夹中说/ sdcard / folder.我想从一个线程中做到这一点.我该怎么做?
解决方法:
如果其他人遇到同样的问题,我就这样做了
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); } if (files != null) 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(in, out); } catch(IOException e) { Log.e("tag", "Failed to copy asset file: " + filename, e); } 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 in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while((read = in.read(buffer)) != -1){ out.write(buffer, 0, read); }}参考:Move file using Java
总结以上是内存溢出为你收集整理的android – 如何将文件从’assets’文件夹复制到SD卡?全部内容,希望文章能够帮你解决android – 如何将文件从’assets’文件夹复制到SD卡?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)