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");