欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

本文實(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ì)有所幫助。

相關(guān)文章

最新評(píng)論