android 多層目錄檔案建立
1.專案中遇到
android path = sdcard/xx/x/..../x/xxx.bin 目錄一開始不存在
RandomAccessFile raf = new RandomAccessFile(path, "rw");
一開始在主流手機上會自動建立檔案的,但是今天新人拿了個破android 手下測試下載時候老出現下載失敗,debug 很久才發現是RandomAccessFile 建立多級檔案目錄的時候造成的,4個以內沒問題,5個以上就出問題了
只能修改程式碼了加入下面先判斷
File file = new File(path);
// 如果資料夾不存在則建立if (!file.getParentFile().exists()) {
System.out.println("//不存在" + file.getParentFile());
file.getParentFile().mkdirs();
} else {
System.out.println("//目錄存在");
}
RandomAccessFile raf = new RandomAccessFile(
"path, "rw");