특정 디렉토리의 공개 갤러리 폴더에 이미지 파일을 쓰려고하는데 파일을 열 수 없다는 오류가 계속 발생합니다. 예배 규칙서.안드로이드의 외부 저장소 갤러리에 이미지를 저장하는 방법
는 내가 지금까지 가지고하는 디렉토리는 응용 프로그램 이름입니다 다음
//set the file path
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + directory;
File outputFile = new File(path,"testing.png");
outputFile.mkdirs();
FileOutputStream out = new FileOutputStream(outputFile);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
입니다. 따라서 응용 프로그램에서 저장 한 모든 사진은 해당 폴더/디렉토리로 이동합니다,하지만 난 디렉토리에 넣어 시도하지 않더라도 나는 오류를
/storage/sdcard0/Pictures/appname/testing.png: open failed: EISDIR (Is a directory)
가 계속하고 파일로 변수 경로를 캐스팅 like
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
나는 사진이 여전히 갤러리에 나타나지 않지만 오류는 나타나지 않는다.
*** Answer 문제는 내가이 코드를 처음 실행했을 때 디렉토리에 파일을 만들기 전에 디렉토리를 만들지 못했기 때문에 testing.png라는 디렉토리를 만들었습니다. 그래서 해결책은 디렉토리가 먼저 당신이 내가 시작했던 것과 같은 실수를 한 경우 스토리지에 가서 수동으로 디렉토리를 삭제해야 할 수도 있으므로
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString() + File.separator + directory;
//directory is a static string variable defined in the class
//make a file with the directory
File outputDir = new File(path);
//create dir if not there
if (!outputDir.exists()) {
outputDir.mkdir();
}
//make another file with the full path AND the image this time, resized is a static string
File outputFile = new File(path+File.separator+resized);
FileOutputStream out = new FileOutputStream(outputFile);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
주처럼 별도의 파일로에 쓸 수 있도록하는 것입니다
때때로 갤러리를 새로 고침해야합니다. ddms를 통해 폴더 경로로 이동하여 새 파일이 만들어 졌는지 확인하십시오. – sachy
그래 내가 그랬어 그 [1] [1] 새 파일이 [포스트]를 참조 스캔에 대해 여러 번 withno 행운 – Brian
: http://stackoverflow.com/questions/4646913/android-how-to -use-mediascannerconnection-scanfile/5815005 # 5815005 – sachy