ファイル操作 [ファイル操作]
ファイル操作は多々あるが、Contextを利用した場合。フォルダが作れないのが最大の欠点だと思う。
//Write ここではBitmapを使っている。
byte[] bytedata = bmp2data(bitmap, Bitmap.CompressFormat.JPEG, 80); OutputStream os = null; try { os = con.openFileOutput(fileName, Context.MODE_PRIVATE); os.write(bytedata, 0, bytedata.length); os.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (os != null) os.close(); } catch (IOException e) { e.printStackTrace(); } }
//Read Bitmapを読み込んでいる
InputStream is; is = con.openFileInput(fileName); bitmap = BitmapFactory.decodeStream(is);
//Delete
con.deleteFile(fileName);
タグ:ファイル操作
コメント 0