我正在制作 android 应用程序..在其中我已将图像字符串编码到外部卡中的外部文件..但是当我读取该文件以显示图像..应用程序崩溃..这是一个代码:
storedpic.setOnClickListener(new View.OnClickListener() {
ImageView storedimageView = (ImageView) findViewById(R.id.imageView3);
public void onClick(View v) {
File sdcard = Environment.getExternalStorageDirectory();
File readfile = new File(sdcard, "myfile.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(readfile));
String test;
while (true) {
test = br.readLine();
// readLine() returns null if no more lines in the file
byte[] bytarray = Base64.decode(test, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory
.decodeByteArray(bytarray, 0, bytarray.length);
storedimageView.setImageBitmap(bmimage);
if (test == null)
break;
}
}
catch (IOException e) {
Toast.makeText(getBaseContext(), "Can't read a file", Toast.LENGTH_LONG).show();
}
}
});