안드로이드에 카메라에서 이미지를 저장해야합니다. 난 매니페스트 기록 외부 저장 권한을 사용하고 난 대신 mkdirs의 나도 MKDIR 시도안드로이드 mkdirs가 작동하지 않습니다
File dir = new File(Environment.getExternalStorageDirectory(), "Test");
if (!dir.exists() || !dir.isDirectory())
dir.mkdirs();
String path = dir.getAbsolutePath();
Log.d(TAG, path); //log show the path
File file = new File(dir.getAbsolutePath() + "/Pic.jpg");
Log.d(TAG, file.getAbsolutePath()); //again path is shown here
outStream = new FileOutputStream(file);
outStream.write(bytes);
outStream.close();
Log.d(TAG, "onPictureTaken - wrote bytes: " + bytes.length); //fail here
} catch (FileNotFoundException e) {
Log.d(TAG, "not done"); //error is here (this exception is thrown)
} catch (IOException e) {
Log.d(TAG, "not");
} finally { }
코드()와 동일한 결과를 이용하고있다.
코드에서 무엇이 잘못 되었습니까?
덕분에
아마도 [런타임 권한이 구현되지 않았습니다.] (https://stackoverflow.com/questions/32635704/android-permission- 나에게 선언 했더라도). 그 이상, ** 그것을 로깅하지 않고 ** 예외를 잡을 수 없어. Log.d() 호출에 세 번째 매개 변수로'e'를 추가 한 다음 LogCat을 사용하여 충돌과 관련된 Java 스택 추적을 검사하십시오. – CommonsWare
스택 트레이스를 보여 주시겠습니까? – ToYonos
'if (! dir.exists() ||! dir.isDirectory()) dir.mkdirs();'. 나쁜 코드의 좋은 예. 먼저 디렉토리가 아니라면 mkdirs는 해당 파일을 디렉토리로 변환하지 않습니다. 두 번째로 mkdirs의 반환 값이 실패 할 수 있으므로이를 확인해야합니다. 그것은 그 길로 어느 것이 었습니다. – greenapps