0
외부 SD 카드가 없으므로 장치 내부 장치의 External
파티션에 파일을 쓰고 싶습니다.주 외부 저장 장치에 파일을 쓸 수 없습니다.
private String filename = "SampleFile.txt";
private String filepath = "MyFileStorage";
File mySensorData = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
, filepath);
String myData = "";
private void FileWrite(String sensorReading) throws IOException {
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
try {
FileOutputStream fos = new FileOutputStream(mySensorData);
fos.write(sensorReading.getBytes());
fos.close();
Toast.makeText(this, "File written to the external storage.",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
else {
Toast.makeText(this, "Unable to read the external storage.",
Toast.LENGTH_SHORT).show();
}
}
//external storage discrepancies handler
private static boolean isExternalStorageReadOnly() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
return true;
}
return false;
}
private static boolean isExternalStorageAvailable() {
String extStorageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
return true;
}
return false;
}
내가 지속적으로 모니터에 Unable to read the external storage.
토스트,이 오류가 무엇입니까 :
W/System.err: Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
문제는 여기
내 코드? 감사합니다. .
대신 getExternalStoragePublicDirectory의) getExternalStorageDirectory을 (시도. 또는 환경 .DIRECTORY_MOVIES –
@RandykaYudhistira 작동하지 않습니다! –