import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
/*将assets文件夹下的数据库写入SD卡中
* @author Dave */
public class WriteToSD {
private Context context;
String filePath = android.os.Environment.getExternalStorageDirectory()+"/weather";
public WriteToSD(Context context){
this.context = context;
if(!isExist()){
write();
}
}
private void write(){
InputStream inputStream;
try {
inputStream = context.getResources().getAssets().open("addressId.db");
File file = new File(filePath);
if(!file.exists()){
file.mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(filePath + "/database.db");
byte[] buffer = new byte[512];
int count = 0;
while((count = inputStream.read(buffer)) > 0){
fileOutputStream.write(buffer, 0 ,count);
}
fileOutputStream.flush();
fileOutputStream.close();
inputStream.close();
System.out.println("success");
} catch (IOException e) {
e.printStackTrace();
}
}
private boolean isExist(){
File file = new File(filePath + "/database.db");
if(file.exists()){
return true;
}else{
return false;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有