国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
android開發(fā)中的文件操作
最新歷史版本 :android開發(fā)中的文件操作
  • 編輯時間: 歷史版本編輯者:火鳳青鸞
  • 內(nèi)容長度:圖片數(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();//相對

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

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

  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ū)懭?,會覆蓋原數(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();

  }

  }

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
16. 文件的保存與讀取
android中的文件操作詳解以及內(nèi)部存儲和外部存儲
Android 私有文件夾 文件的寫入與讀取 2
Android
android-文件存儲
徹底理解android中的內(nèi)部存儲與外部存儲
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服