Internal Storage内部存储

发布时间:2020-07-26 10:11:12 作者:鹭岛猥琐男
来源:网络 阅读:284

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

}


推荐阅读:
  1. ORA-00600: internal error code, arguments: [25027]
  2. MySQL Internal Temporary

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

storage internal 内部存储

上一篇:MySQL——全量,增量备份与恢复(实战篇!)

下一篇:vue axios的transformRequest和transformResponse的QA

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》