【Java学习|黑马笔记|Day21】IO流|缓冲流,转换流,序列化流,反序列化流,打印流,解压缩流,常用工具包相关用法及练习

标题【Java学习|黑马笔记|Day20】

今天看的是黑马程序员的《Java从入门到起飞》下部的95-118节,笔记包含IO流中的字节、字符缓冲流,转换流,序列化流反序列化流,打印流,解压缩流,常用工具包相关用法及练习


欢迎大家在评论区交流讨论,一起学习共同进步🕵🏻‍♀️

文章目录

    • 标题【Java学习|黑马笔记|Day20】
        • 10)上篇练习
          • 1.拷贝一个文件夹,考虑子文件夹
          • 2.文件加解密
          • 3.修改文件中的数据
        • 11)字节缓冲流
        • 11.1)字节缓冲流拷贝文件(一次读一个字节)
        • 11.2)字节缓冲流拷贝文件(一次读写多个字节)
        • 11.3)底层原理
        • 12)字符缓冲流
        • 13)练习
          • 1.四种拷贝方式效率对比
          • 2.恢复出师表的顺序
          • 3.控制软件运行的次数
        • 14)转换流
        • 14.1)练习
        • 15)序列化流
        • 16)反序列化流/对象操作输入流
        • 17)(反)序列化流的细节
        • 18)练习
        • 19)打印流
        • 19.1)字节打印流
        • 19.2)字符打印流
        • 20.1)解压缩流
        • 20.2)压缩流
        • 21.1)常用工具包Commons-io
        • 21.2)常用工具包-Hutool

接上篇

10)上篇练习
1.拷贝一个文件夹,考虑子文件夹
public class T1 {public static void main(String[] args) throws IOException {//1.数据源File src = new File("D:\\a\\bbb");//2.目的地File dest = new File("D:\\a\\aaa");copydir(src,dest);}private static void copydir(File src, File dest) throws IOException {dest.mkdir();//如果dest不存在就创建一个File[] files = src.listFiles();for (File file : files) {if(file.isFile()){FileInputStream fis = new FileInputStream(file);FileOutputStream fos = new FileOutputStream(new File(dest,file.getName()));byte[] bytes = new byte[1024];int len;while((len = fis.read(bytes)) != -1){fos.write(bytes,0,len);}fos.close();fis.close();}else {copydir(file,new File(dest,file.getName()));}}}
}
2.文件加解密

加密:对原始文件的每一个字节数据进行更改,然后将更改后的数据存储到新的文件中

解密:读取加密之后的问价,按照加密的规则反向操作,编程原始文件

通过异或进行加解密

加密

//^异或 不同为true 一个数异或另一个数两次结果是它本身
//1.创建对象关联原始文件
FileInputStream fis = new FileInputStream("src\\1.jpg");
//2.创建对象关联机密文件
FileOutputStream fos = new FileOutputStream("src\\ency.jpg");
//3.加密处理
int b;
while((b = fis.read()) != -1){fos.write(b ^ 2);
}
fos.close();
fis.close();

解密

//4.解密FileInputStream fis = new FileInputStream("src\\ency.jpg");
FileOutputStream fos = new FileOutputStream("src\\redu.jpg");
int b;
while((b =  fis.read()) != -1){fos.write(b ^ 2);
}
fos.close();
fis.close();
3.修改文件中的数据

排序文件中的数据

public static void main(String[] args) throws IOException {FileReader fr = new FileReader("src\\1.txt");StringBuilder sb = new StringBuilder();int ch;while ((ch = fr.read()) != -1) {sb.append((char)ch);}fr.close();String s = sb.toString();String[] arrStr = s.split("-");Arrays.sort(arrStr);System.out.println(Arrays.toString(arrStr));FileWriter fw = new FileWriter("src\\1.txt");for (int i = 0; i < arrStr.length; i++) {fw.write(arrStr[i]);if(i != arrStr.length-1){fw.write("-");}}fw.close();
}
11)字节缓冲流

在这里插入图片描述

11.1)字节缓冲流拷贝文件(一次读一个字节)

原理:底层自带了长度为8192的缓冲区提高性能

方法名称说明
public BufferedInputStream(InputStream is)把基本流包装成高级流,提高读取数据的性能
public BufferedOutputStream(OutputStream is)把基本流包装成高级流,提高读取数据的性能
public class T1 {public static void main(String[] args) throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("src\\1.txt"));BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("src\\copy.txt"));int b;while((b = bis.read()) != -1){bos.write(b);}bos.close();bis.close();}
}
11.2)字节缓冲流拷贝文件(一次读写多个字节)
public class T1 {public static void main(String[] args) throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("src\\1.txt"));BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("src\\copy.txt"));int len;byte[] bytes = new byte[1024];while((len = bis.read(bytes)) != -1){bos.write(bytes,0,len);}bos.close();bis.close();}
}
11.3)底层原理

在这里插入图片描述

数据源通过基本流自动把数据加载到内存中的缓冲区,缓冲输出流的缓冲区自动把数据传给目的地,int b在两缓冲区之间移动传递数据

为什么节省时间?

因为在内存当中操作速度非常快,int b来回传递的速度可以忽略不计

12)字符缓冲流
方法名称说明
public BufferedReader(Reader r)把基本流包装成高级流,提高读取数据的性能
public BufferedWriter(Writer r)把基本流包装成高级流,提高读取数据的性能

字符缓冲流特有方法

字符缓冲输入流特有方法说明
public String readLine()读取一行数据,如果没有数据可读了会返回null
字符缓冲输出流特有方法说明跨平台的换行
public void newLine()读取一行数据,如果没有数据可读了会返回null

字符缓冲输出流

public class T1 {public static void main(String[] args) throws IOException {//创建对象BufferedReader br = new BufferedReader(new FileReader("src\\1.txt"));//读取数据//readLine细节:在读取时读取一整行读到回车换行结束,//              但是不会把回车换行读到内存中String line;while((line = br.readLine()) != null){System.out.println(line);}//释放资源br.close();}
}

字符缓冲输入流

public class T1 {public static void main(String[] args) throws IOException {//创建对象BufferedWriter bw = new BufferedWriter(new FileWriter("src\\2.txt"));//读取数据bw.write("123456789");bw.newLine();//释放资源bw.close();}
}

总结

在这里插入图片描述

13)练习
1.四种拷贝方式效率对比

字节基本流一次读一个字节

字节基本流一次读一个字节数组

字节缓冲流一次读一个字节

字节缓冲流一个读一个字节数组

public class T1 {public static void main(String[] args) throws IOException {long start = System.currentTimeMillis();//method1(); //method2();method3();//method4();long end = System.currentTimeMillis();System.out.println((end - start) / 1000.0 + "秒");}private static void method4() throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("src\\1.txt"));BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("src\\2.txt"));int len;byte[] bytes = new byte[1024];while ((len = bis.read(bytes)) != -1) {bos.write(bytes);}bos.close();bis.close();}private static void method3() throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("src\\1.txt"));BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("src\\2.txt"));int b;while ((b = bis.read()) != -1) {bos.write(b);}bos.close();bis.close();}private static void method2() throws IOException {FileInputStream fis = new FileInputStream("src\\1.txt");FileOutputStream fos = new FileOutputStream("src\\2.txt");int len;byte[] bytes = new byte[1024];while ((len = fis.read(bytes)) != -1) {fos.write(len);}fos.close();fis.close();}private static void method1() throws IOException {FileInputStream fis = new FileInputStream("src\\1.txt");FileOutputStream fos = new FileOutputStream("src\\2.txt");int b;while ((b = fis.read()) != -1) {fos.write(b);}fos.close();fis.close();}}
2.恢复出师表的顺序
public class T1 {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new FileReader("D:\\BaiduNetdiskDownload\\csb.txt"));String line;ArrayList<String> list = new ArrayList<>();while((line = br.readLine()) != null){list.add(line);}br.close();Collections.sort(list, new Comparator<String>() {@Overridepublic int compare(String o1, String o2) {//获取o1、o2序号return Integer.parseInt(o1.split("\\.")[0]) - Integer.parseInt(o2.split("\\.")[0]);}});BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\BaiduNetdiskDownload\\csbnew.txt"));for (String s : list) {bw.write(s);bw.newLine();}bw.close();}
}
3.控制软件运行的次数

在这里插入图片描述

public class T1 {public static void main(String[] args) throws IOException {//定义一个计数器保存在本地文件中,程序停止数据不会消失//1.读取文件的数字count//原则:IO随用随建,不用就关闭BufferedReader br = new BufferedReader(new FileReader("src\\count.txt"));String line = br.readLine();br.close();int count = Integer.parseInt(line);count++;//又运行一次//2.判断 > 3 不能运行if(count <= 3){System.out.println("欢迎使用,第" + count + "次免费");}else {System.out.println("只能免费使用三次,请注册会员");}//bw创建在用的时候,如果创建到br下会清空文件使程序出错BufferedWriter bw = new BufferedWriter(new FileWriter("src\\count.txt"));bw.write(count + "");//把数字转换成字符bw.close();}
}
14)转换流

字符流和字节流之间的桥梁

InputStreamReader字节流 转换为 字符流,并可以指定字符编码(如 UTF-8、GBK 等)来正确解析字节。

OutputStreamWriter字符流写入到字节流中,并可以指定字符编码(如 UTF-8、GBK 等)。
在这里插入图片描述

eg:利用转换流按照指定字符编码读取

public class T1 {public static void main(String[] args) throws IOException {//法一(已淘汰)InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\a\\1.txt"),"GBK");int ch;while((ch = isr.read()) != -1){System.out.print((char)ch);}isr.close();//法二:用FileReaderFileReader fr = new FileReader("D:\\a\\1.txt", Charset.forName("GBK"));int ch1;while((ch1 = fr.read()) != -1){System.out.print((char)ch1);}fr.close();}
}
14.1)练习

利用字节流读取文件中的数据,每次读一行

public class T1 {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\a\\1.txt")));String str = br.readLine();System.out.println(str);br.close();}
}
15)序列化流

在这里插入图片描述

序列化流/对象操作输出流:可以把Java中的对象写到本地文件中

构造方法说明
public ObjectOutputStream(OubtputStream out)把基本流包装成高级流
成员方法说明
public final void writeObject(Object obj)把对象序列化写出到文件中
public class T1 {public static void main(String[] args) throws IOException {Student stu = new Student("zs",23);//创建序列化流对象ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src\\1.txt"));//细节:使用对象输出流保存到文件时会出现NotSerializableException异常//     解决方案:需要让Javabean类实现Serializable接口//写出数据oos.writeObject(stu);//关闭资源oos.close();}
}
//Serializable接口里没有抽象方法,是标记型接口
//一旦实现了找个接口表示当前的Student类可以被序列化
public class Student implements Serializable {private String name;private int age;//......}
16)反序列化流/对象操作输入流

可以把序列化到本地文件中的对象读取到程序中来

构造方法说明
public ObjectInputStream(InputStream out)把基本流升级为高级流
成员方法说明
public Object readObject()把序列化到本地的对象读取到程序中
public class T1 {public static void main(String[] args) throws IOException, ClassNotFoundException {//创建对象ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src//1.txt"));//读取数据Student o = (Student)ois.readObject();//返回值类型是Object 可以强转成Student//打印对象System.out.println(o);//释放资源ois.close();}
}
17)(反)序列化流的细节

创建一个对象的序列化流后,又修改对象的成员变量会报错,报错原因:文件中的版本号跟Javabean的版本号不匹配

处理方法:固定版本号

public static Student implements Serializable{private static final long 版本号 = 1L;private Stirng name;private int age;private String address;
}

在这里插入图片描述

18)练习

读写多个对象,个数不确定

//序列化流
public class T1 {public static void main(String[] args) throws IOException, ClassNotFoundException {Student s1 = new Student("zs",23);Student s2 = new Student("ls",24);Student s3 = new Student("ww",25);ArrayList<Student> list = new ArrayList<>();list.add(s1);list.add(s2);list.add(s3);ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src\\1.txt"));oos.writeObject(list);oos.close();}
}
//反序列化流
public class T2 {public static void main(String[] args) throws IOException, ClassNotFoundException {ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src\\1.txt"));ArrayList<Student> list = (ArrayList<Student>) ois.readObject();for (Student student : list) {System.out.println(student);}ois.close();}
}
19)打印流

分类PrintStream字节打印流,PrintWriter字符打印流

特点

  1. 打印流只操作文件目的地,不操作数据源
  2. 特有的写出方法,数据原样写出 eg:打印97 文件中97
19.1)字节打印流
构造方法说明
public PrintStream(OutputStream/File/String)灌流字节输出流/文件/文件路径
public PrintStream(String fileName,Charset charset)指定字符编码
public PrintStream(OutputStream out,bollean autoFlush)自动刷新
public PrintStream(OutputStream out,boolean autoFlush,String encoding)指定字符编码且自动刷新

字节流底层没有缓冲区,开不开自动刷新都一样

成员方法说明
public void write(int b)将指定的字节写出
public void println(Xxx xx)特有:打印任意数据,自动刷新,自动换行
public void print(Xxx xx)特有:打印任意数据,不换行
public void printf(String format,Object…args)特有:带有占位符的打印语句,不换行
PrintStream ps = new PrintStream(new FileOutputStream("src\\1.txt"),true,Charset.forName("UTF-8"));ps.println(97);//写出+自动刷新+自动换行
ps.print(true);
ps.printf(" %s 1 %s","a","b");ps.close();
//占位符
//%n 换行
//%c 大写
//%b boolean类型的
//%d 小数的占位符
19.2)字符打印流
构造方法说明
public PrintWrite(Write/File/String)关联字节输出流/文件/文件路径
public PrintWrite(String fileName,Charset charset)指定字符编码
public PrintWrite(Write w,boolean autoFlush)自动刷新
public PrintWrite(OutputStream out,bollean autoFlush,Charset charset)指定字符编码且自动刷新

字符流底层有缓冲区,相应自动刷新需要开启

成员方法说明
public void write(int b)将指定的字节写出
public void println(Xxx xx)特有:打印任意数据,自动刷新,自动换行
public void print(Xxx xx)特有:打印任意数据,不换行
public void printf(String format,Object…args)特有:带有占位符的打印语句,不换行
PrintWriter pw = new PrintWriter(new FileWriter("src\\1.txt"),true);
pw.println("a");
pw.print("b");
pw.printf(" %s 1 %s","a","b");pw.close();

打印流的应用场景

    //获取打印流的对象,此打印流在虚拟机,不能关闭,在系统中唯一启动时由虚拟机创建默认指向控制台//特殊的打印流,系统中的标准输出流PrintStream ps = System.out;//调用打印输出流的println写出数据自动换行自动刷新ps.println("123");ps.close();System.out.println("asd");//关闭后sout也不能打印了
20.1)解压缩流

解压本质:把每一个ZipEntry按照层级拷贝到本地另一个文件夹中

public class T1 {public static void main(String[] args) throws IOException {//1.创建一个File表示要解压的压缩包File src = new File("D:\\a\\1.zip");//2.创建一个File表示是解压的目的地File dest = new File("D:\\a");//调用方法unzip(src, dest);}public static void unzip(File src,File dest) throws IOException {//创建一个解压缩流用来读取压缩包中的数据ZipInputStream zip = new ZipInputStream(new FileInputStream(src));//获取压缩包里每一个zipEntry对象ZipEntry entry;//getNextEntry可以获取压缩包里的所有文件文件夹while((entry = zip.getNextEntry()) != null) {System.out.println(entry);//如果是文件夹需要再dest创建一个同样的文件夹//如果是文件拷贝到dest中if(entry.isDirectory()) {File file = new File(dest, entry.toString());file.mkdirs();//创建多层目录}else {FileOutputStream fos = new FileOutputStream(new File(dest, entry.toString()));int b;while((b=zip.read()) != -1) {fos.write(b);}fos.close();//表示压缩包中的一个文件处理完毕了}}zip.close();}
}
20.2)压缩流

压缩单个文件

public class T1 {public static void main(String[] args) throws IOException {//1.创建File对象表示要压缩的文件File src = new File("D:\\a\\1.txt");//2.创建File对象表示压缩包的位置File dest = new File("D:\\a\\");//调用方法toZip(src,dest);}public static void toZip(File src, File dest) throws IOException {//1.创建压缩流关联压缩包ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(dest,"a.zip")));//2.把ZipEntry对象表示压缩包里每一个对象ZipEntry entry = new ZipEntry("a.txt");//3.把对象放到压缩包里zos.putNextEntry(entry);//4.把src文件中的数据写到压缩包中FileInputStream fis = new FileInputStream(src);int b;while((b = fis.read()) != -1) {zos.write(b);}fis.close();zos.closeEntry();zos.close();}
}

压缩整个文件夹

public class T1 {public static void main(String[] args) throws IOException {//1.创建File对象表示要压缩的文件File src = new File("D:\\a\\aaa");//2.创建File对象表示元素包的父级目录File destParent = src.getParentFile();//3.创建File对象表示压缩包的位置File dest = new File( destParent,src.getName() +".zip");//4.创建压缩流关联压缩包ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(dest));//5.获取src里面的每一个文件,变成ZipEntry对象放到压缩包中toZip(src,zos,src.getName());zos.close();}public static void toZip(File src, ZipOutputStream zos,String name) throws IOException {//1.进入src文件夹File[]  files = src.listFiles();for (File file : files) {if(file.isFile()){//变成ZipEntry对象放到压缩包ZipEntry entry = new ZipEntry(name + "\\" + file.getName());zos.putNextEntry(entry);//读取文件中的数据写到压缩包FileInputStream fis = new FileInputStream(file);int b;while((b = fis.read()) != -1){zos.write(b);}fis.close();zos.closeEntry();}else {toZip(file,zos,name + "\\"+file.getName());}}}
}
21.1)常用工具包Commons-io

是一组IO操作的开源工具包

作业:提高IO流的开发效率

使用步骤

  1. 在项目中创建一个文件夹:lib
  2. jar包复制粘贴到lib文件夹
  3. 右键点击jar包,选择Add as Library -> 点击OK
  4. 在类中导包使用

在这里插入图片描述

在这里插入图片描述

eg

File src = new File("src\\1.txt");
File dest = new File("src\\2.txt");
FileUtils.copyFile(src,dest);
21.2)常用工具包-Hutool

在这里插入图片描述

(笔记内容主要基于黑马程序员的课程讲解,旨在加深理解和便于日后复习)
在这里插入图片描述

希望这篇笔记能对大家的学习有所帮助,有啥不对的地方欢迎大佬们在评论区

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/90351.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/90351.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

API网关原理与使用场景详解

一、API网关核心原理 1. 架构定位 #mermaid-svg-hpDCWfqoiLcVvTzq {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-hpDCWfqoiLcVvTzq .error-icon{fill:#552222;}#mermaid-svg-hpDCWfqoiLcVvTzq .error-text{fill:#5…

OSPF路由协议——上

OSPF路由协议 RIP的不足 以跳数评估的路由并非最优路径如果RTA选择s0/0传输&#xff0c;传输需时会大大缩短为3s 最大跳数为16跳&#xff0c;导致网络尺度小RIP协议限制网络直径不能超过16跳&#xff0c;并且16跳为不可达。 收敛速度慢 RIP 定期路由更新 更新计时器&#xff1a…

(LeetCode 面试经典 150 题) 219. 存在重复元素 II (哈希表)

题目&#xff1a;219. 存在重复元素 II 思路&#xff1a;哈希表&#xff0c;时间复杂度0(n)。 哈希表记录每个数最新的下标&#xff0c;遇到符合要求的返回true即可。 C版本&#xff1a; class Solution { public:bool containsNearbyDuplicate(vector<int>& nums,…

Cookies 详解及其与 Session 的协同工作

Cookies 详解及其与 Session 的协同工作 一、Cookies 的本质与作用 1. 什么是 Cookies&#xff1f; Cookies 是由服务器发送到用户浏览器并存储在本地的小型文本文件。核心特性&#xff1a; 存储位置&#xff1a;客户端浏览器数据形式&#xff1a;键值对字符串&#xff08;最大…

DeepSeek Janus Pro本地部署与调用

step1、Janus模型下载与项目部署 创建文件夹autodl-tmp https://github.com/deepseek-ai/Janus?tabreadme-ov-file# janusflow 查看是否安装了git&#xff0c;没有安装的话安装一下&#xff0c;或者是直接github上下载&#xff0c;上传到服务器&#xff0c;然后解压 git --v…

【Elasticsearch】BM25的discount_overlaps参数

discount_overlaps 是 Elasticsearch/Lucene 相似度模型&#xff08;Similarity&#xff09;里的一个布尔参数&#xff0c;用来决定&#xff1a;> 在计算文档长度归一化因子&#xff08;norm&#xff09;时&#xff0c;是否忽略“重叠 token”&#xff08;即位置增量 positi…

Linux | LVS--Linux虚拟服务器知识点(上)

一. 集群与分布式1.1 系统性能扩展方式当系统面临性能瓶颈时&#xff0c;通常有以下两种主流扩展思路&#xff1a;Scale Up&#xff08;向上扩展&#xff09;&#xff1a;通过增强单台服务器的硬件配置来提升性能&#xff0c;这种方式简单直接&#xff0c;但受限于硬件物理极限…

【Linux-云原生-笔记】keepalived相关

一、概念Keepalived 是一个用 C 语言编写的、轻量级的高可用性和负载均衡解决方案软件。 它的主要目标是在基于 Linux 的系统上提供简单而强大的故障转移功能&#xff0c;并可以结合 Linux Virtual Server 提供负载均衡。1、Keepalived 主要提供两大功能&#xff1a;高可用性&a…

计算机网络:概述层---计算机网络的组成和功能

&#x1f310; 计算机网络基础全景梳理&#xff1a;组成、功能与核心机制 &#x1f4c5; 更新时间&#xff1a;2025年7月21日 &#x1f3f7;️ 标签&#xff1a;计算机网络 | 网络组成 | 分布式 | 负载均衡 | 资源共享 | 网络可靠性 | 计网基础 文章目录前言一、组成1.从组成部…

Linux中scp命令传输文件到服务器报错

上传本地文件到Linux服务器使用scp命令报错解决办法使用scp命令报错 Could not resolve hostname e: Name or service not known 解决办法 不使用登录服务器的工具传输&#xff0c;打开本地cmd&#xff0c;使用scp命令传输即可。 scp E:\dcm-admin.jar root127.0.0.1:/

历史数据分析——国药现代

医药板块走势分析: 从月线级别来看 2008年11月到2021年2月,月线上走出了两个震荡中枢的月线级别2085-20349的上涨段; 2021年2月到2024年9月,月线上走出了20349-6702的下跌段; 目前月线级别放巨量,总体还在震荡区间内,后续还有震荡和上涨的概率。 从周线级别来看 从…

#Linux内存管理# 在一个播放系统中同时打开几十个不同的高清视频文件,发现播放有些卡顿,打开视频文件是用mmap函数,请简单分析原因。

在播放系统中同时使用mmap打开几十个高清视频文件出现卡顿&#xff0c;主要原因如下&#xff1a;1. 内存映射&#xff08;mmap&#xff09;的缺页中断开销按需加载机制&#xff1a;mmap将文件映射到虚拟地址空间&#xff0c;但实际数据加载由“缺页中断&#xff08;Page Fault&…

AI黑科技:GAN如何生成逼真人脸

GAN的概念 GAN(Generative Adversarial Network,生成对抗网络)是一种深度学习模型,由生成器(Generator)和判别器(Discriminator)两部分组成。生成器负责生成 synthetic data(如假图像、文本等),判别器则试图区分生成数据和真实数据。两者通过对抗训练不断优化,最终…

FireFox一些设置

firefox后台打开新的链接&#xff0c;例如中键打开一个链接 地址栏输入about:config 找到下面三项&#xff0c;全部设为true browser.tabs.loadInBackground browser.tabs.loadDivertedInBackground browser.tabs.loadBookmarksInBackground 参考&#xff1a;FireFox/chrome…

【黑马SpringCloud微服务开发与实战】(六)分布式事务

1. 什么是分布式事务下单失败&#xff0c;购物车还被清理了。不符合一致性。2. seata的架构和原理3. 部署TC服务docker network ls docker inspect mysql mysql 在hm-net下&#xff0c;这里我的ncaos不是跟着视频配的&#xff0c;因此需要。 docker network connect hm-net nac…

【力扣】第15题:三数之和

原文链接&#xff1a;15. 三数之和 - 力扣&#xff08;LeetCode&#xff09; 思路解析 双指针&#xff1a; &#xff08;1&#xff09;头尾指针对应值相加如果大于目标值(target)&#xff0c;那么只能尾指针-1&#xff1b;如果小于target&#xff0c;那么只能头指针1。 &#x…

Linux PCI总线子系统

The Linux Kernel Archives Linux PCI总线子系统 — The Linux Kernel documentation

LeetCode热题100--24. 两两交换链表中的节点--中等

1. 题目 给你一个链表&#xff0c;两两交换其中相邻的节点&#xff0c;并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题&#xff08;即&#xff0c;只能进行节点交换&#xff09;。 示例 1&#xff1a; 输入&#xff1a;head [1,2,3,4] 输出&#x…

京东视觉算法面试30问全景精解

京东视觉算法面试30问全景精解 ——零售智能 供应链创新 工业落地:京东视觉算法面试核心考点全览 前言 京东作为中国领先的零售科技企业,在智能物流、供应链管理、智能仓储、商品识别、工业质检等领域持续推动视觉AI的创新与大规模落地。京东视觉算法岗位面试不仅关注候…

【设计模式】观察者模式 (发布-订阅模式,模型-视图模式,源-监听器模式,从属者模式)

观察者模式&#xff08;Observer Pattern&#xff09;详解一、观察者模式简介 观察者模式&#xff08;Observer Pattern&#xff09; 是一种 行为型设计模式&#xff08;对象行为型模式&#xff09;&#xff0c;它定义了一种一对多的依赖关系&#xff0c;让多个观察者对象同时监…