首先

添加读写sd卡权限:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><!--读本地文件权限-->    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!--写本地文件权限-->

把一个文本push进Android系统目录下
如:adb push test.txt /sdcard/Downloadn/

要是txt内容过多,需要起一个线程,如:

       new Thread(new Runnable() {            @Override            public void run() {                try {                    //指定文件                    InputStreamReader isr = new InputStreamReader(new FileInputStream("文件地址"), "UTF8");//UTF8格式                    BufferedReader br = new BufferedReader(isr);                    String text = br.readLine();                    String str = "";                    while ((str = br.readLine()) != null) {                        str += "";                        //筛选内容                        if (str != null) {                            str.contains("xx");                            String str_1 = str.substring(str.indexOf("x")+1,str.indexOf(".")+2);                      outputToFile("test2.txt",str_1+"\n");//输出内容到指定文件,如没有该文件,自动创建。                        }                    }                } catch (IOException e) {                    e.printStackTrace();                }            }        }).start();

输出的信息保存进另一个文件中

    public void outputToFile(String file_name, String txt)//file_name = 文件名, txt = 内容 {        try {            FileOutputStream outSTr = new FileOutputStream(new File("保存的路径"+file_name), true);            BufferedOutputStream Buff = new BufferedOutputStream(outSTr);            Buff.write(txt.getBytes());            Buff.flush();            Buff.close();        } catch (IOException e) {            e.printStackTrace();        }    }

结束

更多相关文章

  1. Android中文API(137) —— LocalSocket
  2. android 自动打包
  3. android 扫描SD卡与系统文件
  4. Android之Adapter用法总结
  5. [Android] 无法创建项目问题解决
  6. WebView显示网页
  7. Android(安卓)系统搜索框(有浏览记录)
  8. Android(安卓)http协议实现文件下载
  9. NPM 和webpack 的基础使用

随机推荐

  1. OkHttp使用教程
  2. android的四大组件解析
  3. adb remount bash: /usr/local/bin/adb:
  4. android资源文件之:shape详解
  5. [Android应用开发]添加了两个Button后发
  6. android app 缓存路径
  7. Android中点击事件的四种写法详解
  8. android system.img,ramdisk.img,boot.im
  9. android使用AlertDialog提示 Unable to a
  10. android linux 命令