메신저 sdCard에 데이터를 저장하려고합니다. getExternalFilesDir을 사용하여 externalStorage의 앱 디렉토리에서 개인적으로 저장하려고했지만 나에게 nullPointerException을주었습니다.이미지를 sdcard에 저장 안드로이드 디렉토리 문제
FileOutputStream os;
dirName = "/mydirectory/";
try {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)){
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + dirName);
dir.mkdirs();
//File file = new File(this.getExternalFilesDir(null), this.dirName+fileName); //this function give null pointer exception so im using other one
File file = new File(dir, dirName+fileName);
os = new FileOutputStream(file);
}else{
os = context.openFileOutput(fileName, MODE_PRIVATE);
}
resizedBitmap.compress(CompressFormat.PNG, 100, os);
os.flush();
os.close();
}catch(Exception e){
}
오류 로그 :
java.io.FileNotFoundException : /mnt/sdcard/mvc/mvc/myfile2.png 내가 원하는 사용자 정의 디렉토리에 파일을 저장은 나에게 오류를주고 자신을 명명하기 (그런 파일이나 디렉토리가 없음)
전달중인 매개 변수를 모든 파일 및 디렉토리 호출에 기록하십시오. 아마도 자신이 생각하는대로하지 않을 것입니다. 또한 모든 반환 값을 확인하여 작동하지 않는지 확인합니다. –
전체 스택 트레이스를 보유하고 있습니까? – thoredge