zoukankan      html  css  js  c++  java
  • 安卓数据持久化

    //文件类型

    void save(String string){ FileOutputStream out=null; BufferedWriter writer = null; try{ out = openFileOutput("data", Context.MODE_APPEND); writer = new BufferedWriter(new OutputStreamWriter(out)); writer.write(string); }catch (IOException e) { e.printStackTrace(); }finally { try { if(writer!=null){ writer.close(); } }catch (IOException e){ e.printStackTrace(); } } } public String load(){ FileInputStream in =null; BufferedReader reader = null; StringBuilder content= new StringBuilder(); try{ in =openFileInput("data"); reader =new BufferedReader(new InputStreamReader(in)); String line=""; while ((line=reader.readLine())!=null){ content.append(line); } }catch (IOException e){ e.printStackTrace(); }finally { if(reader!=null){ try{ reader.close(); }catch (IOException e){ e.printStackTrace(); } } } return content.toString(); }
      SharedPreferences.Editor editor  = getSharedPreferences("data",MODE_PRIVATE).edit();
            editor.putString("name","tom");
            editor.putInt("age",28);
            editor.putBoolean("married",false);
            editor.apply();
    
            SharedPreferences pref= getSharedPreferences("data",MODE_PRIVATE);
            String name = pref.getString("name","");
            int age = pref.getInt("age",0);
            Boolean married = pref.getBoolean("married",false);
            Log.d(TAG, "onCreate: "+name);
            Log.d(TAG, "onCreate: "+age);
            Log.d(TAG, "onCreate: "+married);
    

      

  • 相关阅读:
    多线程-工作组模式
    iOS端架构、基本组成与使用说明
    iOS,Core Animation--负责视图的复合功能
    Container Views
    IOS UIView 01-View开始深入 绘制像素到屏幕上
    View Programming Guide for iOS
    UI绘图与信息、样式
    iOS绘图框架CoreGraphics分析
    iOS开发系列--打造自己的“美图秀秀”
    Array与NSArray关系
  • 原文地址:https://www.cnblogs.com/norm/p/8204991.html
Copyright © 2011-2022 走看看