zoukankan      html  css  js  c++  java
  • android文件读写模板 java程序员

    写文件:
    
    FileOutputStream out = null;
    try
    {
        out = openFileOutput(filename, MODE_PRIVATE);
        byte[] content = (写入的文本).getBytes();
        out.write(content);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        if(out != null)
        {
            try
            {
                out.close();
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }
        }
    }
    
    读文件:
    
    FileInputStream input = null;
    try
    {
        input = openFileInput(filename);
        Byte []buffer = new Byte[1024];
        StringBuilder sb = new StringBuilder();
        while(input.read(buffer) != -1)
        {
            String content_part = new String(buffer, 0, buffer.length);
            sb.append(content_part);
        }
    }
    catch(FileNotFoundException e)
    {
        e.printStackTrace();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        if(input != null)
        {
            try
            {
                input.close();
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }
        }
    }
    

  • 相关阅读:
    POI2014 洛谷P3574 FarmCraft 题解
    JZOJ 3468 OSU!题解
    sublime配置C++编译环境
    本地配置gitee
    数论基础
    HDU
    HDU-3033 I love sneakers! 题解
    HDU-4341 Gold miner 题解
    HDU
    MyBatis框架及原理分析
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215855.html
Copyright © 2011-2022 走看看