I’m trying to write an image file to a directory on my sd card and it doesn’t appear to be working. When I read the image into the bytearray it does not write the contents to the sd card. The code is as follows:
public void addRecord(){
long id;
out = new ByteArrayOutputStream(128);
bm.compress(CompressFormat.JPEG, 100, out);
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard + File.separator + "studentpics");
if(!dir.exists()){
dir.mkdir();
}
File f = new File(sdCard + File.separator + dir.toString() + File.separator + strStudentName + ".png");
try {
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
fos.write(out.toByteArray());
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Try to replace
With