파일 권한을 읽기 전용으로 설정하려고 시도했지만 아무 효과가없는 것으로 보입니다.Android File.setReadyOnly()가 예상대로 작동하지 않습니다.
File file = new File(mContext.getExternalFilesDir(null), "testFile");
if (!file.exists()){
file.createNewFile();
}
boolean successful = file.setReadOnly();
boolean canRead = file.canRead();
boolean canWrite = file.canWrite();
Log.d("TAG", String.format("Permissions write successful: %s for file: %s", successful, file.getAbsolutePath()));
Log.d("TAG", String.format("Can read: %s , Can write: %s", canRead, canWrite));
콘솔 출력 위를 수행하는 것입니다 :
D/TAG: Permissions write successful: true for file: /storage/emulated/0/Android/data/package.name/files/testFile
D/TAG: Can read: true , Can write: true
는 비록 그 파일에 기록 할 수 없어야 여기에 코드입니다. 여기에 어떤 문제가 있습니까?
당신은 또한 그것에 쓸 수 있습니다. –