博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 操作文件
阅读量:6932 次
发布时间:2019-06-27

本文共 1282 字,大约阅读时间需要 4 分钟。

public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        try{             write("prothro.sq","welcome to the hell");             String str = read("prothro.sq");             Log.v("sq", str);                     }catch(IOException e){e.printStackTrace();}           }                    String read(String fileName) throws IOException    {        FileInputStream fis = this.openFileInput(fileName);        // openFileInput(String FileName) 是android 取得 FileInputStream 的方法        StringBuilder sb = new StringBuilder();        //相当于 StringBuffered                byte[] buff = new byte[1024];    //存放数据的字节数组        int hasRed = 0;                                        //像java 那样读取文件内容        while((hasRed = fis.read(buff))>0)        {            sb.append(new String(buff,0,hasRed));        }        return sb.toString();    }                        void write(String fileName,String content) throws IOException    {        FileOutputStream fos = this.openFileOutput(fileName, MODE_APPEND);        PrintStream ps = new PrintStream(fos); //将 FileOutputStream 包装成 打印流        ps.println(content);    //打印到文件中去        ps.close();    }

 

转载于:https://www.cnblogs.com/laoquans/archive/2013/05/08/3066349.html

你可能感兴趣的文章
Javascript正则表达式难点、重点
查看>>
梁胜博士亲解Rancher 2.0:K8s之上的Rancher魔法
查看>>
一起学并发编程 - 简易线程池实现
查看>>
HTTP_HOST 和 SERVER_NAME 的区别
查看>>
【160天】尚学堂高琪Java300集视频精华笔记(129)
查看>>
【新技术】不用开发者账号申请ios证书真机调试
查看>>
再谈CVE-2017-7047 Triple_Fetch和iOS 10.3.2沙盒逃逸
查看>>
在vue.js中省市选择
查看>>
谈谈Spanner和F1
查看>>
Python图片爬取方法总结
查看>>
leetcode63. Unique Paths II
查看>>
优质的 Vue 开源项目 - 收藏集 - 掘金
查看>>
【翻译】关于回调地狱
查看>>
使用Gradle第一次构建Web应用
查看>>
html的嵌套规则
查看>>
神经病啊!——微信同层播放器接(踩)入(坑)总结
查看>>
详解Session
查看>>
CI类实现session基本用法
查看>>
Kubelet源码分析(一):启动流程分析
查看>>
Ktor 1.0发布:JetBrains推出的Kotlin Web框架
查看>>