前言: ????作者简介:我是笑霸final,一名热爱技术的在校学生。 ????个人主页:?笑霸final的主页? ????系列专栏::本文写在java专栏 ????如果文章知识点有错误的地方,请指正!和大家一起学习,一起进步???? ????如果感觉博主的文章还不错的话,????点赞???? + ????关注???? + ????收藏????
JavaIO流入门2??上节内容????IO流的分类????利用io流完成对文件的拷贝??上节内容
JavaIO流入门1文件File链接
IO流的分类
数据单位分类:字节流 、字符流流向分类:输出流、输入流角色不同:节点流、处理流/包装流
根据数据单位分类
1.字节流分类 字节流用来处理二进制文件最好
字节输入流??InputStream??? 字节输出流 ??OutputStream??
1.字符流流分类 字符流处理文本文件
字符输入流??Reader??? 字符输入流: ??Writer??
??可见这4个也都抽象类,也就是说不能直接创建对象的??
利用io流完成对文件的拷贝
要求: 在f盘中,把图篇01.png’拷贝到C盘目录
拷贝前:
代码
package com.final_.copy_;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/** * @autor 笑霸fianl~ * 欢迎访问GitHub:https://github.com/XBfinal * 欢迎访问Gitee:https://gitee.com/XBfianl */public class copy_ { public static void main(String[] args) { String filepath=”F:\\01.png”;//目标文件位置 //创建输入流 FileInputStream fileInputStream=null; //创建文件输出流 FileOutputStream fileOutputStream=null; try { fileInputStream=new FileInputStream(filepath); fileOutputStream=new FileOutputStream(“c:\\01.png”);//目标地址 byte[] by=new byte[1024];//经典1024; int i=0; while((i=fileInputStream.read(by))!=-1){ fileOutputStream.write(by,0,i); } } catch (IOException e) { e.printStackTrace(); } finally { try { fileInputStream.close(); fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }}
运行后
人生好如足球赛,看自家总是无奈,对人家总是优待,