关于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(),这句加了,就抛异常,但是我觉得,总不能不关吧 线程问题 android GridView绑定显示SD卡的图片,怎样使显示的顺序按编号显示呢 【【【】】】SD卡路劲求助【【【】】】 怎样截获其他程序的触摸事件,或模拟轨迹球 手机本地能播放3GP 网络地址播放不了~~~~~ 100分求可用的android程序自动更新例程,要含注释 新手遇到的一个问题! 如何修改来电联系人的头像 关于socket通信的问题? selector使用出现问题 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);
}
}
}