• 字节流读写非文本文件(图片、视频等)
@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. HDU - 6128

    题意略: 题解:二次剩余板子题 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) //#pra ...

  2. python中检测mysql的主键唯一性异常

    有两种方法: 1.直接检测是什么异常(查mysql文档找出异常代码) import os import mysql_operate.mysql_connect as mysql import re d ...

  3. 自定义UICollectionViewLayout之CATransform3D

    1.自定义UICollectionViewLayout旋转效果 之前有自定义UICollectionViewLayout(适用于多个section),本文是一个对cell进行CATransform3D ...

  4. java面向对象特征 — 一句话概括

    java基础学习总结之基本特征,最开始学习的时候,是形而上的理解,用了3年多,再回头看,理解起来颇为顺理成章 语言学习大概就是这样一种规律,学习,不甚解,应用,应用,渐深入人心,回头一看,恍然一悟 最 ...

  5. Mysql千万级数据性能调优配置

    背景: 笔者的源数据一张表大概7000多万条,数据大小36G,索引6G,加起来表空间有40G+,类似的表有4张,总计2亿多条 数据库mysql,引擎为innodb,版本5.7,服务器内存256G,物理 ...

  6. Python学习day34-面向对象和网络编程总结

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  7. TensorFlow实战Google深度学习框架-人工智能教程-自学人工智能的第二天-深度学习

    自学人工智能的第一天 "TensorFlow 是谷歌 2015 年开源的主流深度学习框架,目前已得到广泛应用.本书为 TensorFlow 入门参考书,旨在帮助读者以快速.有效的方式上手 T ...

  8. linux crontab定时任务运行shell脚本(shell执行sql文件)

    https://www.cnblogs.com/tiankongjava/p/6106743.html 今天做个linux定时任务(每晚12点把表汇总). 顺便写个博客记录一下~~ 为什么用linux ...

  9. Leetcode962. Maximum Width最大宽度坡 Ramp

    给定一个整数数组 A,坡是元组 (i, j),其中  i < j 且 A[i] <= A[j].这样的坡的宽度为 j - i. 找出 A 中的坡的最大宽度,如果不存在,返回 0 . 示例 ...

  10. Django项目:CRM(客户关系管理系统)--63--53PerfectCRM实现CRM客户报名流程缴费

    #urls.py """PerfectCRM URL Configuration The `urlpatterns` list routes URLs to views. ...