У меня есть небольшая проблема с созданием каталога и сохранением файла в моем приложении для Android. Я использую этот кусок кода для этого:
String filename = "MyApp/MediaTag/MediaTag-"+objectId+".png";
File file = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos;
fos = new FileOutputStream(file);
fos.write(mediaTagBuffer);
fos.flush();
fos.close();
Но это бросает исключение:
java.io.FileNotFoundException:/mnt/sdcard/MyApp/MediaCard/MediaCard-0.png(Нет такого файла или каталога)
на этой строке: fos = new FileOutputStream(file);
Если я задаю имя файла: "MyApp/MediaTag-"+objectId+"
, он будет работать, но если я попытаюсь создать и сохранить файл в другой каталог, это исключает исключение. Итак, любые идеи, что я делаю неправильно?
И еще один вопрос: есть ли способ сделать мои файлы приватными во внешнем хранилище, чтобы пользователь не мог видеть их в галерее, только если он подключил свое устройство как Disk Drive
?