RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
InternalStorage内部存储

package com.example.zzwinternalstorage;

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的五大连池网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

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;
   }

}


分享标题:InternalStorage内部存储
文章位置:http://cqwzjz.cn/article/jdjdpc.html