我想寫一個圖像文件到我的SD卡上的目錄,它似乎並沒有工作。當我將圖像讀入字節數組時,它不會將內容寫入SD卡。代碼如下:圖像文件沒有被寫入SD卡
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();
}
}
你什麼錯誤? – MByD