国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android開發(fā)實(shí)現(xiàn)讀取Assets下文件及文件寫入存儲(chǔ)卡的方法

2019-12-12 01:50:39
字體:
供稿:網(wǎng)友

本文實(shí)例講述了Android開發(fā)實(shí)現(xiàn)讀取Assets下文件及文件寫入存儲(chǔ)卡的方法。分享給大家供大家參考,具體如下:

調(diào)用一個(gè)反編譯的.so文件,查看起加密和解密情況,需要解析上萬的數(shù)組,而so文件加密解密都是通過Byte來進(jìn)行,又需要把String字符串轉(zhuǎn)化為 Byte,當(dāng)把數(shù)據(jù)直接寫在代碼中就會(huì)提示多Byte數(shù)組過大。最后把數(shù)組寫到Assets文件加下,讀取txt文本文件。

讀取Assets方法如下:

public String getFromAssets(String fileName) {    String result = "";    try {      InputStream in = getResources().getAssets().open(fileName);      // 獲取文件的字節(jié)數(shù)      int lenght = in.available();      // 創(chuàng)建byte數(shù)組      byte[] buffer = new byte[lenght];      // 將文件中的數(shù)據(jù)讀到byte數(shù)組中      in.read(buffer);      result = EncodingUtils.getString(buffer, ENCODING);    } catch (Exception e) {      e.printStackTrace();    }    return result;}

然后

String strEn = getFromAssets("encode.txt");

txt中的文本文件是str,str,str這種形式,然后把

String[] encode1 = strEn.split(","); 

通過字符串把 讀取的字符串轉(zhuǎn)化成字符串?dāng)?shù)組。

for(int i=0;i<encode1.length;i++){  sendString = encode1[i];  //       sbuf.append(sendString+",");  try {    sendBytes = sendString.getBytes("UTF8");    byte[] s = Base64Encoder.B64Encode(sendBytes);    str = new String(s, "ISO-8859-1");  } catch (UnsupportedEncodingException e) {    // TODO Auto-generated catch block    e.printStackTrace();  }  sbuf.append(str);  sbuf.append(",");}

String.split具有分割數(shù)組的作用,它已某一個(gè)特殊符號(hào)為分界點(diǎn)然后進(jìn)行數(shù)組分割。

再把加密后的字符串寫到本地文件。方法如下

public String saveInfo2File(String mString) {    StringBuffer sb = new StringBuffer();    try {      long timestamp = System.currentTimeMillis();      String fileName = "encut" + ".txt";      if (Environment.getExternalStorageState().equals(          Environment.MEDIA_MOUNTED)) {        String spath = Environment.getExternalStorageDirectory()            .getPath() + "/A1/";        File sdir = new File(spath);        if (!sdir.exists())          sdir.mkdirs();        FileOutputStream fos = new FileOutputStream(spath + fileName);        sb.append(mString);        fos.write(sb.toString().getBytes());        fos.close();      }      return fileName;    } catch (Exception e) {    }    return null;}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 文安县| 江西省| 东海县| 杭锦旗| 南宫市| 九龙城区| 渭南市| 阿鲁科尔沁旗| 莲花县| 隆尧县| 临海市| 台前县| 洪江市| 潮州市| 安西县| 阿合奇县| 瑞昌市| 贵溪市| 醴陵市| 嘉兴市| 林芝县| 哈巴河县| 都昌县| 宁武县| 宝山区| 资阳市| 兴和县| 五华县| 晋江市| 双城市| 嘉祥县| 卢氏县| 南昌市| 克拉玛依市| 吴江市| 文登市| 鄂温| 万山特区| 南江县| 松桃| 七台河市|