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

  • 相关阅读:
    基于nginx结合openssl实现https
    更新续约与重新登陆
    DNS服务器
    ELK日志分析系统。
    OpenSSH远程控制
    DHCP配置
    DHCP服务概述
    网络服务
    磁盘配额
    磁盘配额
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215855.html
Copyright © 2011-2022 走看看