• 字节流读写非文本文件(图片、视频等)
@Test
public void test5(){
File srcFile = new File("FLAMING MOUNTAIN.JPG");
File destFile = new File("FLAMING MOUNTAIN1.JPG");
FileInputStream fis = null;
FileOutputStream fos = null; try {
//字节输入输出流
fis = new FileInputStream(srcFile);
fos = new FileOutputStream(destFile); //复制
byte[] buffer = new byte[5];
int len;
while ((len = fis.read(buffer)) != -1){
fos.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

  

IO流9 --- 使用FileInputStream和FileOutputStream读写非文本文件 --- 技术搬运工(尚硅谷)的更多相关文章

  1. java中OutputStream字节流与字符流InputStreamReader 每一种基本IO流BufferedOutputStream,FileInputStream,FileOutputStream,BufferedInputStream,BufferedReader,BufferedWriter,FileInputStream,FileReader,FileWriter,InputStr

    BufferedOutputStream,FileInputStream,FileOutputStream,BufferedInputStream,BufferedReader,BufferedWri ...

  2. IO流15 --- 数据流操作Java语言的基本数据类型 --- 技术搬运工(尚硅谷)

    写入数据 @Test public void test10() throws IOException { DataOutputStream dos = new DataOutputStream(new ...

  3. IO流6 --- FileReader中使用read(char[] cbuf)读入数据 --- 技术搬运工(尚硅谷)

    FileReader 字符输入流 @Test public void test2(){ File file = new File("hello.txt"); FileReader ...

  4. java io系列07之 FileInputStream和FileOutputStream

    本章介绍FileInputStream 和 FileOutputStream 转载请注明出处:http://www.cnblogs.com/skywang12345/p/io_07.html File ...

  5. JAVA FILE or I/O学习 - I/O流操作:FileInputStream、FileOutputStream、ObjectInputStream、ObjectOutputStream、InputStreamReader、OutputStreamWriter等

    public class IOStreamKnow { /*********************************文件读写方式:字节流**************************** ...

  6. Java中用FileInputStream和FileOutputStream读写txt文件,文件内容乱码的问题,另附循环代码小错误

    乱码问题大概就是编码格式不一样,搜了很多都是这么说的,修改编码解决乱码问题链接: https://blog.csdn.net/weixin_42496466/article/details/81189 ...

  7. Java里的IO流里的FileInputStream 的读取并在前打印行数!

    大家好!!新人求罩! import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException ...

  8. IO流18 --- RandomAccessFile实现数据的读写操作 --- 技术搬运工(尚硅谷)

    RandomAccessFile实例化时,需要设置读写模式 示例:复制文件 @Test public void test16() throws IOException { RandomAccessFi ...

  9. JavaEE基础(二十)/IO流

    1.IO流(IO流概述及其分类) 1.概念 IO流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 Java用于操作流的类都在IO包中 流按流向分为两种:输入流,输出流. 流按操作类型分 ...

随机推荐

  1. MySQL数据库(安装+增删改查)

    一. 安装 下载地址 : https://dev.mysql.com/downloads/mysql/ 1. 安装步骤 (1) 选择5.7版本 (2) 针对操作系统的不同下载不同的版本 (3) 解压 ...

  2. 阿里巴巴大数据产品最新特性介绍--机器学习PAI

    以下内容根据演讲视频以及PPT整理而成. 本次分享主要围绕以下五个方面: PAI产品简介 自定义算法上传 数加智能生态市场 AutoML2.0自动调参 AutoLearning自动学习 一.PAI产品 ...

  3. kafka数据祸福和failover

    k CAP帽子理论. consistency:一致性 Availability:可用性 partition tolerance:分区容忍型 CA :mysql oracle(抛弃了网络分区) CP:h ...

  4. 周期串Uva455 P37 3-4

    A character string is said to have period k if it can be formed by concatenating one or more repetit ...

  5. NtQuerySystemInformation 枚举进程

    函数原型: NTSTATUS WINAPI NtQuerySystemInformation(    _In_      SYSTEM_INFORMATION_CLASS SystemInformat ...

  6. linux命令行实用快捷键

    打开一个命令行窗口:ctrl+alt+t 在已有的命令行窗口上开启一个新的tab:ctrl+shift+t

  7. 搭建nodejs代理服务器,从而解决跨域问题

    先在同级处新建js文件(app.js) 使用时npm 安装 Node.js 模块语法 也就是对应的文件所在地“npm install”一下 然后安装对应需要的模块: expresspathreques ...

  8. SQL有意思的面试题

    1.中软国际 SQL行转列  变成   --数据准备create table t_test( year int, month int, sale int, primary key (year, mon ...

  9. svn里update以后还是有红色的感叹号怎么办

    不用那么麻烦,直接还原就行了,客户端是TortoiseSVN的话,在该文件或文件夹上点右键,选择TortoiseSVN——revert有时还原之后系统反应没那么快,还是显示红色感叹号,刷新几下就正常了 ...

  10. oauth2使用心得-----基本概念以及认证服务器搭建

    应用场景 我们假设你有一个“云笔记”产品,并提供了“云笔记服务”和“云相册服务”,此时用户需要在不同的设备(PC.Android.iPhone.TV.Watch)上去访问这些“资源”(笔记,图片) 那 ...