1读写字符文件
  BufferedReader br=new BufferedReader(new FileReader("文件路径"));
  BufferedWriter bw=new BufferedWriter(new FileWriter("文件路径",boolean));

   

public static void main (String[] args) throws Exception{

BufferedWriter bw=new BufferedWriter(new FileWriter("src/a.txt");

BufferedReader br=new BufferedReader(new FileReader("src/d.txt"));

String str=null;

while((str=br.readLine())!=-1){

System.out.println(str);

}

bw.close();

br.close();

}

 

2读写字节文件
  DataInputStream dis=new DataInputStream(new FileInputStream("文件路径"));
  DataOutputStream dos=new DataOutputStream(new FileOutputStream("文件路径"));

   

public static void main(String[] args) throws Exception {
DataInputStream dis=new DataInputStream(new FileInputStream("src/a.jpg"));
int a=dis.read();
System.out.println(a);
dis.close();

DataOutputStream dos=new DataOutputStream(new FileOutputStream("src/b.jpg"));
dos.write(255);
dos.close();

//复制a.jpg--->b.jpg
DataInputStream dis1=new DataInputStream(new FileInputStream("src/a.jpg"));
DataOutputStream dos1=new DataOutputStream(new FileOutputStream("src/b.jpg"));
int b;
while((b=dis.read())!=-1){
dos.write(b);
}
dis.close();
dos.close();
}

 

3读取整个字符文件
  String str=null;
  while((str=br.readLine())!=-1){
    System.out.println(str);
  }
4读取整个字节文件
  int b;
  while((b=dis.read())!=-1){
    System.out.println(b);
  }

File I/O的总结的更多相关文章

  1. 记一个mvn奇怪错误: Archive for required library: 'D:/mvn/repos/junit/junit/3.8.1/junit-3.8.1.jar' in project 'xxx' cannot be read or is not a valid ZIP file

    我的maven 项目有一个红色感叹号, 而且Problems 存在 errors : Description Resource Path Location Type Archive for requi ...

  2. HTML中上传与读取图片或文件(input file)----在路上(25)

    input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...

  3. logstash file输入,无输出原因与解决办法

    1.现象 很多同学在用logstash input 为file的时候,经常会出现如下问题:配置文件无误,logstash有时一直停留在等待输入的界面 2.解释 logstash作为日志分析的管道,在实 ...

  4. input[tyle="file"]样式修改及上传文件名显示

    默认的上传样式我们总觉得不太好看,根据需求总想改成和上下结构统一的风格…… 实现方法和思路: 1.在input元素外加a超链接标签 2.给a标签设置按钮样式 3.设置input[type='file' ...

  5. .NET平台开源项目速览(16)C#写PDF文件类库PDF File Writer介绍

    1年前,我在文章:这些.NET开源项目你知道吗?.NET平台开源文档与报表处理组件集合(三)中(第9个项目),给大家推荐了一个开源免费的PDF读写组件 PDFSharp,PDFSharp我2年前就看过 ...

  6. [笔记]HAproxy reload config file with uninterrupt session

    HAProxy is a high performance load balancer. It is very light-weight, and free, making it a great op ...

  7. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  8. input type='file'上传控件假样式

    采用bootstrap框架样式 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...

  9. FILE文件流的中fopen、fread、fseek、fclose的使用

    FILE文件流用于对文件的快速操作,主要的操作函数有fopen.fseek.fread.fclose,在对文件结构比较清楚时使用这几个函数会比较快捷的得到文件中具体位置的数据,提取对我们有用的信息,满 ...

  10. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

随机推荐

  1. mysql-5.6.22的安装步骤

    一.环境与下载地址: 1.系统下载地址: http://mirrors.sohu.com/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-bin-DVD1.iso 2 ...

  2. matlab出错及改正

    1 使用小波分析时,出现下面错误: 错误使用 wavedec需要的 X 应为 矢量.出错 wavedec (line 34)validateattributes(x,{'numeric'},{'vec ...

  3. html-3,table 表格标签 tr th td caption thead tbody tfoot 的简单使用

    <!-- table border='1' style="border-collapse:collapse;" border 表格的像素宽度 border-collapse: ...

  4. c#的yield return

    4.1 迭代器块 一个迭代器块(iterator block)是一个能够产生有序的值序列的块.迭代器块和普通语句块的区别就是其中出现的一个或多个yield语句. yield return语句产生迭代的 ...

  5. bug最后汇总-2018/08/03

    一.对于点击后请求时间过长的按钮 现象:容易给用户点击无效的错觉,从而导致多次点击,从而发出多个相同请求,这显然是不符合我们意愿的 解决: 用户点击发出多个请求:加个锁,当用户点击后,将锁关闭,使用户 ...

  6. MySQL-5.7 游标及DECLARE

    1.cursor游标 用来声明一个数据集 游标的声明必须在变量和条件声明之后,在handler声明之前 游标特性: 不灵敏:服务器可以或不复制其结果 只读:不可更新 不可滚动的:只能在一个方向上遍历, ...

  7. ubuntu linux 1604 编译安装tesseract-ocr 4.0

    主要参考官方的编译,梳理一下整个流程 Linux The build instructions for Linux also apply to other UNIX like operating sy ...

  8. 添加一个vue全局守卫,主要用于用户登录时候验证

    //注册一个全局守卫,作用是在路由跳转钱,对路由进行判断,防止未登录用户跳转到其他页面 router.beforeEach((to, from, next) => { let token = l ...

  9. 单片机、嵌入式CAN通信原理

    工作原理: 单片机里内置了一个FIFO(先进先出)芯片,需要发送什么报文,就往这个芯片里写.比如有两个单片机作为CAN节点,A节点往自己的FIFO中写CAN报文,B节点往自己的FIFO中写CAN报文. ...

  10. Rreact Native 常见错误总结

    1.invariant violation:expected a component class,got[object object]        创建自定义组件首字母要大写,否则会报错.     ...