设为首页收藏本站

移动叔叔

搜索
查看: 639|回复: 0
打印 上一主题 下一主题

[教程] 联想 A765e 安卓程序raw文件放在sd卡代码实例

[复制链接]
跳转到指定楼层
楼主
发表于 2013-4-17 09:17:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
 有时候我们需要把程序的raw文件放在sd卡中,其实有时候这样做可以释放资源,下面来看代码:
  void copyAssets()
  {
  String[] files;
  try
  {
  files = this.getResources().getAssets().list("");
  }
  catch (IOException e1)
  {
  return;
  }
  if(!mWorkingPath.exists())
  {
  if(!mWorkingPath.mkdirs())
  {
  new AlertDialog.Builder(this)
  .setTitle(R.string.ERROR)
  .setMessage(R.string.FAILED_DIR_CREATE)
  .setPositiveButton(android.R.string.ok, new OnClickListener(){
  @Override
  public void onClick(DialogInterface dialog, int which)
  {
  dialog.dismiss();
  }
  })
  .create()
  .show();
  }
  }
  for(int i = 0; i < files.length; i++)
  {
  try
  {
  String fileName = files;
  if(fileName.compareTo("images") == 0 ||
  fileName.compareTo("sounds") == 0 ||
  fileName.compareTo("webkit") == 0)
  {
  continue;
  }
  File outFile = new File(mWorkingPath, fileName);
  if(outFile.exists()) continue;
  InputStream in = getAssets().open(fileName);
  OutputStream out = new FileOutputStream(outFile);
  // Transfer bytes from in to out
  byte[] buf = new byte[1024];
  int len;
  while ((len = in.read(buf)) > 0)
  {
  out.write(buf, 0, len);
  }
  in.close();
  out.close();
  }
  catch (FileNotFoundException e)
  {
  e.printStackTrace();
  }
  catch (IOException e)
  {
  e.printStackTrace();
  }
  }

-






您需要登录后才可以回帖 登录 | 注册

关闭

站长推荐上一条 /1 下一条

© 2008-2024 移动叔叔. 版权所有,专业的网络售后平台 ( 闽ICP备18006692号-3 )

商务合作点击这里给我发消息|Email:service@mobileuncle.com|手机版|移动叔叔     

GMT+8, 2024-6-8 13:23 , Processed in 0.127992 second(s), 12 queries , Gzip On, Memcache On.

返回顶部