SSブログ

ファイル操作 [ファイル操作]

ファイル操作は多々あるが、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);


 





nice!(1)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

リソースの最適化設定画面 ブログトップ

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。