try FileInputStream and FileOutputSteam both throw exception
try {
FileOutputStream out = new FileOutputStream("p1");
pictureTaken.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
and
case R.id.open:
ImageView im = (ImageView) findViewById(R.id.im);
try {
FileInputStream in = new FileInputStream("p1");
BufferedInputStream buf = new BufferedInputStream(in);
byte[] bitMapA= new byte[buf.available()];
buf.read(bitMapA);
Bitmap bM = BitmapFactory.decodeByteArray(bitMapA, 0, bitMapA.length);
im.setImageBitmap(bM);
if (in != null) {
in.close();
}
if (buf != null) {
buf.close();
}
} catch (Exception e) {
e.printStackTrace();
}
break;
Both try, but they don't pass in de-bug, they just got to the catch.开发者_如何学C.. I got most of these parts online and modified them to my needs, but even so, it all makes sense and works in my head. Just don't see why it throws the exception.
It sounds like its on Android, and from the path you are using (p1
) you are just trying to save to a file in the app's running folder. Broadly speaking you CAN NOT write to the whatever directory that is. You'll want to do something like this:
FileOutputStream out = openFileOutput ("p1", MODE_WORLD_WRITABLE);
in the first code block, and then:
FileInputStream in = openFileInput("p1");
in the second code block.
精彩评论