亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android獲取assets文件夾中的數(shù)據(jù)并寫入SD卡示例

 更新時間:2014年07月24日 14:55:19   投稿:shichen2014  
這篇文章主要介紹了Android獲取assets文件夾中的數(shù)據(jù)并寫入SD卡示例,對初學(xué)Android開發(fā)的朋友來說是一個很實用的功能,需要的朋友可以參考下

本文示例主要實現(xiàn)了Android獲取assets文件夾中的數(shù)據(jù)并將其寫入到SD卡中,該程序?qū)崿F(xiàn)的步驟主要為:首先讀取assets文件夾中的數(shù)據(jù)庫,再將其寫入到SD存儲卡中。

完整示例代碼如下:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
/*將assets文件夾下的數(shù)據(jù)庫寫入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;
 }
 }
}

相關(guān)文章

最新評論