InternalStorage內(nèi)部存儲

package com.example.zzwinternalstorage;

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的五大連池網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity
{
   private TextView tv;

   public void btn_save(View v)
   {
       FileOutputStream fos = null;
       try
       {
           fos = openFileOutput("zzw.json", MODE_PRIVATE);
           String name = "我是誰";
           fos.write(name.getBytes());
       }
       catch (FileNotFoundException e)
       {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       catch (IOException e)
       {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       finally
       {
           if (fos != null)
           {
               try
               {
                   fos.close();
               }
               catch (IOException e)
               {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
               }
           }
       }

   }

   public void btn_read(View v)
   {
       FileInputStream fis = null;
       ByteArrayBuffer arrayBuffer = new ByteArrayBuffer(1024);
       try
       {
           fis = openFileInput("zzw.json");
           int len = 0;
           byte[] buffer = new byte[1024];
           while (-1 != (len = fis.read(buffer)))
           {
               arrayBuffer.append(buffer, 0, len);
           }
       }
       catch (FileNotFoundException e)
       {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       catch (IOException e)
       {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }finally{
           if(fis!=null){
               try
               {
                   fis.close();
               }
               catch (IOException e)
               {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
               }
           }
       }
       String str=new String(arrayBuffer.toByteArray(), 0, arrayBuffer.length());
       tv.setText(str);

   }

   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       tv = (TextView) findViewById(R.id.textView1);
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu)
   {
       // Inflate the menu; this adds items to the action bar if it is present.
       getMenuInflater().inflate(R.menu.main, menu);
       return true;
   }

}

網(wǎng)頁名稱:InternalStorage內(nèi)部存儲
當(dāng)前網(wǎng)址:http://bm7419.com/article32/jdjdpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站排名、品牌網(wǎng)站制作、面包屑導(dǎo)航、網(wǎng)站改版、網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司