小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

android開(kāi)發(fā)中的文件操作

 妮妮816 2012-03-22
最新歷史版本 :android開(kāi)發(fā)中的文件操作
  • 編輯時(shí)間: 歷史版本編輯者:火鳳青鸞
  • 內(nèi)容長(zhǎng)度:圖片數(shù):目錄數(shù):
  • 修改原因:

android的文件操作要有權(quán)限:

  判斷SD卡是否插入

  Environment.getExternalStorageState().equals(

  android.os.Environment.MEDIA_MOUNTED);

  獲得sd卡根目錄

  File skRoot = Environment.getExternalStorageDirectory();

  獲得私有根目錄

  File fileRoot = Context.getFilesDir()+"\";

  確定或獲得文件夾和文件路徑

  String path = File.getPath();//相對(duì)

  String path = File.getAbsoultePath();//絕對(duì)

  獲得文件或文件夾的父目錄

  String parentPath = File.getParent()

  獲得文件或文件夾的名稱:

  String Name = File.getName();

  建立文件或文件夾

  File.createNewFile();//建立文件

  判斷是文件或文件夾

  File.isDirectory()

  列出文件夾下的所有文件和文件夾名

  File[] files = File.listFiles();

  修改文件夾和文件名

  File.renameTo(dest);

  刪除文件夾或文件

  File.delete();

  文件讀寫操作模式

  Context.MODE_PRIVATE:新內(nèi)容覆蓋原內(nèi)容

  Context.MODE_APPEND:新內(nèi)容追加到原內(nèi)容后

  Context.MODE_WORLD_READABLE:允許其他應(yīng)用程序讀取

  Context.MODE_WORLD_WRITEABLE:允許其他應(yīng)用程序?qū)懭?,?huì)覆蓋原數(shù)據(jù)。

  /*** 保存文件

  * @param fileName

  * @param fileContent

  * @throws Exception*/

  public void save(String fileName, String fileContent) throws Exception {

  // Activity的父類的父類就是context,context與其他框架中的context相同為我們以供了一些核心操作工具。

  FileOutputStream fileOutputStream = this.context.openFileOutput(

  fileName, Context.MODE_PRIVATE);

  fileOutputStream.write(fileContent.getBytes());

  }

  /**

  * 讀取文件

  *

  * @param fileName

  * @return

  * @throws Exception

    */

  public String read(String fileName) throws Exception {

  FileInputStream fileInputStream = this.context.openFileInput(fileName);

  ByteArrayOutputStream byteArray = new ByteArrayOutputStream();

  byte[] buffer = new byte[1024];

  int len = 0;

  while ((len = fileInputStream.read(buffer)) > 0) {

  byteArray.write(buffer, 0, len);

  };

  return byteArray.toString();

  }

  }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多