最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2017年10月23日 09:48:14   作者:jia635  
這篇文章主要介紹了Android開發(fā)實現(xiàn)讀取Assets下文件及文件寫入存儲卡的方法,涉及Android文件與目錄的讀取、寫入、轉換等相關操作技巧,需要的朋友可以參考下

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

調(diào)用一個反編譯的.so文件,查看起加密和解密情況,需要解析上萬的數(shù)組,而so文件加密解密都是通過Byte來進行,又需要把String字符串轉化為 Byte,當把數(shù)據(jù)直接寫在代碼中就會提示多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(","); 

通過字符串把 讀取的字符串轉化成字符串數(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ù)組的作用,它已某一個特殊符號為分界點然后進行數(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;
}

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

希望本文所述對大家Android程序設計有所幫助。

相關文章

最新評論

英吉沙县| 同仁县| 沙坪坝区| 固阳县| 望谟县| 温泉县| 郓城县| 江津市| 宣恩县| 南丹县| 阳新县| 荆门市| 梨树县| 融水| 大兴区| 兴城市| 颍上县| 宜兴市| 三都| 三门峡市| 天长市| 柞水县| 远安县| 呼伦贝尔市| 法库县| 南和县| 景德镇市| 黔南| 襄樊市| 陆良县| 景谷| 山西省| 汝南县| 丘北县| 宿迁市| 古田县| 尼木县| 临西县| 神池县| 五寨县| 循化|