关于AssetManager close AssetManager close 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class TestApplicition extends Application { @Override public void onCreate() { super.onCreate(); String sdPath=Environment.getExternalStorageDirectory().getAbsolutePath(); String filePath = sdPath + File.separator + "Test" + File.separator + "img"+File.separator; File file = new File(filePath); if (file.exists()) { Log.i("TestApplicition", "file exists"); } else { Log.i("TestApplicition", "file not exists"); AssetManager am= this.getAssets(); InputStream in=null; OutputStream out=null; try { String imgs[]=am.list("img"); for(String name:imgs){ in= am.open("img"+File.separator+name); out=new FileOutputStream(new File(filePath+name)); copyFile(in, out); out.flush(); out.close(); in.close(); out=null; in=null; } } catch (IOException e) { e.printStackTrace(); } am.close(); } } private void copyFile(InputStream in,OutputStream out) throws IOException{ byte buffer[]=new byte[1024]; while(in.read(buffer)!=-1){ out.write(buffer); } }} am.close(),这句加了,就抛异常,但是我觉得,总不能不关吧 [BK_求助]Android:GoogleMap中的getLastKnownLocation总是返回null 谁有免费的火车票查询接口 关于怎么在android系统中内置可以被用户卸载的apk。 关于android与网站交互的编码问题 在android中嵌入flash如swf,请求高手解答? 请教关于android 调用linux服务器端API问题 android是什么操作系统 好郁闷的问题 关于点击listview的问题 Android开发一个上层APP去升级底层的打印机驱动,可行吗 intent传递信息的问题 android 伪装定位是怎么做的
public class TestApplicition extends Application {
@Override
public void onCreate() {
super.onCreate();
String sdPath=Environment.getExternalStorageDirectory().getAbsolutePath();
String filePath = sdPath + File.separator + "Test" + File.separator + "img"+File.separator;
File file = new File(filePath);
if (file.exists()) {
Log.i("TestApplicition", "file exists");
} else {
Log.i("TestApplicition", "file not exists");
AssetManager am= this.getAssets();
InputStream in=null;
OutputStream out=null;
try {
String imgs[]=am.list("img");
for(String name:imgs){
in= am.open("img"+File.separator+name);
out=new FileOutputStream(new File(filePath+name));
copyFile(in, out);
out.flush();
out.close();
in.close();
out=null;
in=null;
}
} catch (IOException e) {
e.printStackTrace();
}
am.close();
}
}
private void copyFile(InputStream in,OutputStream out) throws IOException{
byte buffer[]=new byte[1024];
while(in.read(buffer)!=-1){
out.write(buffer);
}
}
}