javaIO流实现文件读写

文件写入:

InputStreamReader 
BufferedReader

文件读取:
FileOutputStream 
package javatest.basic22;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader; public class IOReadTest { public static void main(String[] args) {
    //写入文件路径
File f2=new File("c:/add44.txt");
    //读取文件路径
File f=new File("c:/add.txt");
BufferedReader read=null;
FileOutputStream fos=null;
try {
        //读取并解决中文乱码问题
        //创建读取流
InputStreamReader isr = new InputStreamReader(new FileInputStream(f), "UTF-8");
        //开始读取
read = new BufferedReader(isr);
        //创建写入流
fos=new FileOutputStream(f2);
String str=null;
int line=1;
while ((str=read.readLine())!=null) {
System.out.println(str);
        //循环写入
fos.write((str+"\t\n").getBytes());
line++;
}
      //关闭流对象
fos.flush();
fos.close();
read.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if (read!=null) {
try {
fos.flush();
fos.close();
read.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
}

最新文章

  1. CAS学习笔记(一)
  2. MVC5 + EF6 + Bootstrap3 (13) 查看详情、编辑数据、删除数据
  3. 开始学习C++ Templates
  4. Debug with jdb
  5. Share_memory
  6. tomcat - 部署Web应用
  7. BZOJ3397: [Usaco2009 Feb]Surround the Islands 环岛篱笆
  8. [Elasticsearch] 部分匹配 (一) - 前缀查询
  9. 【prim + kruscal 】 最小生成树模板
  10. A Bug's Life(种类并查集)(也是可以用dfs做)
  11. syntax error near unexpected token `do(写的shell脚本出现格式问题)--->1.问题2.展示信息3.解决方案
  12. python学习日记(isinstance和issubclass)
  13. 【codeforces 870F】Paths
  14. python自学第9天,装饰器
  15. 监控.net 网站 Glimpse
  16. React篇-报错信息:warning: Can't call setState (or forceUpdate) on an unmounted component.
  17. CLR总览
  18. MT【74】不可能是哪个函数?
  19. phper必知必会之数组指针(四)
  20. mysql按年度、季度、月度、周、日统计查询的sql语句

热门文章

  1. EpPlus读取生成Excel帮助类+读取csv帮助类+Aspose.Cells生成Excel帮助类
  2. crawler_浅谈网络爬虫
  3. UML之轻松入门(2)-掌握Junit,让我们的开发更高效
  4. INF 右安装驱动程序和卸载
  5. iOS:Block写递归
  6. Git@OSC & SSH配置
  7. 堆VS栈
  8. 【动态规划】leetcode - Maximal Square
  9. springmvc实现long-pulling技术
  10. lambda 表达式 自定义查询