我试图将位图保存到私人应用程序目录中的特定文件夹,但是android没有。我可以保存主目录中的文件,我可以创建子目录,但我无法将文件保存到子目录。我在这里使用的方法是:
public void saveBitMap(String fileName, Bitmap bitMap, String album){
//Creating the subdirectory. This works
File albumDir=new File(getFilesDir(), album);
albumDir.mkdirs();
albumDir.setWritable(true);
albumDir.setWritable(true);
fileName = albumDir.getAbsolutePath()+"/"+fileName;
//Creating the file in the subdirectory. This doesn't work
FileOutputStream outputStream;
try {
outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
bitMap.compress(CompressFormat.PNG, 90, outputStream);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
//Checking that the files and folders have been saved
File dir = getFilesDir();
for(File f: dir.listFiles()){
Log.d("ggg", f.getName());
if(f.isDirectory()){
Log.d("ggg",f.list().length+"");
for(String g:f.list()){
Log.d("ggg", g +" "+ f);
}
}
}
}