迁安做网站教育培训机构设计图

news/2025/10/3 17:34:27/文章来源:
迁安做网站,教育培训机构设计图,下载教学设计的网站,上海创意型网站建设Java核心类库篇6——IO 1、File 1.1、构造方法 方法声明功能介绍public File(File parent, String child)从父抽象路径名和子路径名字符串创建新的 File实例public File(String pathname)通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例public File(String pa…Java核心类库篇6——IO 1、File 1.1、构造方法 方法声明功能介绍public File(File parent, String child)从父抽象路径名和子路径名字符串创建新的 File实例public File(String pathname)通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例public File(String parent, String child)从父路径名字符串和子路径名字符串创建新的File实例public File(URI uri)通过将给定的file:URI转换为抽象路径名来创建新的File实例 1.2、方法 方法声明功能介绍public boolean exists()测试此抽象路径名表示的文件或目录是否存在public boolean exists()测试此抽象路径名表示的文件或目录是否存在public long length()返回由此抽象路径名表示的文件的长度public long lastModified()用于获取文件的最后一次修改时间public String getAbsolutePath()用于获取绝对路径信息public boolean delete()用于删除文件当删除目录时要求是空目录public boolean createNewFile()用于创建新的空文件public boolean mkdir()用于创建目录public boolean mkdirs()用于创建多级目录public File[] listFiles()获取该目录下的所有内容public boolean isFile()判断是否为文件public boolean isDirectory()判断是否为目录public File[] listFiles(FileFilter filter)获取目录下满足筛选器的所有内容 2、IO IO就是Input和Output的简写也就是输入和输出的含义 2.1、IO分类 按读写数据的基本单位 字节流以字节为单位进行数据读写的流可以读写任意类型的文件字符流以字符(2个字节)为单位进行数据读写的流只能读写文本文件 按读写数据的方向不同 输入流从文件中读取数据内容输入到程序中也就是读文件输出流将程序中的数据内容输出到文件中也就是写文件 按流的角色 节点流直接和输入输出源对接的流处理流需要建立在节点流的基础之上的流 2.2、IO流的体系结构 红色为抽象类 蓝色为节点流必须直接与指定的物理节点关联 分类字节输入流字节输出流字符输入流字符输出流抽象基类InputStreamOutputStreamReaderWriter访问文件FileInputStreamFileOutputStreamFileReaderFileWriter访问数组ByteArrayInputStreamByteArrayOutputStreamCharArrayReaderCharArrayWriter访问管道PipedInputStreamPipedOutputStreamPipedReaderPipedWriter访问字符串————StringReaderStringWriter缓冲流BufferedInputStreamBufferedOutputStreamBufferedReaderBufferedWriter转换流————InputStreamReaderOutputStreamWriter对象流ObjectInputStreamObjectOutputStream————打印流——PrintStream——PrintWriterFilterInputStreamFilterOutputStreamFilterReaderFilterWriter推回输入流PushbackInputStream——PushbackReader——特殊流DataInputStreamDataOutputStream———— 2.3、FileInputStream 逐个字节读 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileInputStream fileInputStream new FileInputStream(file);int l 0;while ((lfileInputStream.read())!-1){System.out.println((char)l);}fileInputStream.close();} }建立缓冲区读 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileInputStream fileInputStream new FileInputStream(file);byte[] bnew byte[1024];int l 0;while ((lfileInputStream.read(b))!-1){System.out.println(new String(b,0,l));}fileInputStream.close();} }2.4、FileOutputStream 写入文件 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileOutputStream fileOutputStream new FileOutputStream(file);String strhello world, i am ruoye!;byte[] bytes str.getBytes();fileOutputStream.write(bytes);fileOutputStream.close();} }追加内容 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileOutputStream fileOutputStream new FileOutputStream(file,true);String strhello world, i am ruoye!;byte[] bytes str.getBytes();fileOutputStream.write(bytes);fileOutputStream.close();} }2.5、FileReader 逐个字符读 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileReader fileReader new FileReader(file);int l 0;while ((lfileReader.read())!-1){System.out.println((char)l);}fileReader.close();} }建立缓冲区读 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileReader fileReader new FileReader(file);char[] bnew char[1024];int l 0;while ((lfileReader.read(b))!-1){System.out.println(new String(b,0,l));}fileReader.close();} }2.6、FileWriter 写入文件 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileWriter fileWriter new FileWriter(file);String str你好世界;fileWriter.write(str);fileWriter.close();} }追加内容 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileWriter fileWriter new FileWriter(file,true);String str你好世界;fileWriter.append(str);fileWriter.close();} }2.7、转换流 public class Test {public static void main(String[] args) throws IOException {InputStreamReader inputStreamReader new InputStreamReader(new FileInputStream(new File(D:\\a.txt)));int l 0;while ((linputStreamReader.read())!-1){System.out.println((char)l);}inputStreamReader.close();} } public class Test {public static void main(String[] args) throws IOException {OutputStreamWriter outputStreamWriter new OutputStreamWriter(new FileOutputStream(new File(D:\\a.txt)));String strhello wordld;outputStreamWriter.write(str);outputStreamWriter.close();} } 2.8、缓冲流 public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileInputStream fileInputStream new FileInputStream(file);BufferedInputStream bufferedInputStream new BufferedInputStream(fileInputStream);byte[] bytesnew byte[1024];int l 0;while ((lfileInputStream.read(bytes))!-1){System.out.println(new String(bytes,0,l));}fileInputStream.close();} } public class Test {public static void main(String[] args) throws IOException {String pathD:\\a.txt;File file new File(path);FileOutputStream fileOutputStream new FileOutputStream(file);BufferedOutputStream bufferedOutputStream new BufferedOutputStream(fileOutputStream);String strhello world, i am ruoye!;byte[] bytes str.getBytes();bufferedOutputStream.write(bytes);bufferedOutputStream.close();fileOutputStream.close();} } writer和reader同上 2.9、Data流 2.9.1、DataInputStream read(byte b[])—从数据输入流读取数据存储到字节数组b中read(byte b[],int off,in len)—从数据输入流中读取数据存储到数组b里面,位置从off开始,长度为len个字节readFully(byte b[])—从数据输入流中循环读取b.length个字节到数组b中readFully(byte b[],int off,in len )—从数据输入流中循环读取len个字节到字节数组b中.从b的off位置开始skipBytes(int b)—跳过n个字节readBoolean()—从数据输入流读取布尔类型的值readByte()—从数据输入流中读取一个字节readUnsignedByte()—从数据输入流中读取一个无符号的字节,返回值转换成int类型readShort()—从数据输入流读取一个short类型数据readUnsignedShort()—从数据输入流读取一个无符号的short类型数据readChar()—从数据输入流中读取一个字符数据readInt()—从数据输入流中读取一个int类型数据readLong()—从数据输入流中读取一个long类型的数据readFloat()—从数据输入流中读取一个float类型的数据readDouble()—从数据输入流中读取一个double类型的数据readUTF()—从数据输入流中读取用UTF-8格式编码的UniCode字符格式的字符串 public class Test {public static void main(String[] args) throws IOException {DataInputStream dataInputStream new DataInputStream(new FileInputStream(D:\\a.txt));System.out.println(dataInputStream.readUTF());System.out.println(dataInputStream.readInt());System.out.println(dataInputStream.readBoolean());System.out.println(dataInputStream.readShort());System.out.println(dataInputStream.readLong());System.out.println(dataInputStream.readDouble());dataInputStream.close();} } 2.9.2、DataOutputStream intCount(int value)—数据输出流增加的字节数write(int b)—将int类型的b写到数据输出流中write(byte b[],int off, int len)—将字节数组b中off位置开始,len个长度写到数据输出流中flush()—刷新数据输出流writeBoolean()—将布尔类型的数据写到数据输出流中,底层是转化成一个字节写到基础输出流中writeByte(int v)—将一个字节写到数据输出流中(实际是基础输出流)writeShort(int v)—将一个short类型的数据写到数据输出流中,底层将v转换2个字节写到基础输出流中writeChar(int v)—将一个charl类型的数据写到数据输出流中,底层是将v转换成2个字节写到基础输出流中writeInt(int v)—将一个int类型的数据写到数据输出流中,底层将4个字节写到基础输出流中writeLong(long v)—将一个long类型的数据写到数据输出流中,底层将8个字节写到基础输出流中writeFloat(flloat v)—将一个float类型的数据写到数据输出流中,底层会将float转换成int类型,写到基础输出流中writeDouble(double v)—将一个double类型的数据写到数据输出流中,底层会将double转换成long类型,写到基础输出流中writeBytes(String s)—将字符串按照字节顺序写到基础输出流中writeChars(String s)—将字符串按照字符顺序写到基础输出流中writeUTF(String str)—以机器无关的方式使用utf-8编码方式将字符串写到基础输出流中size()—写到数据输出流中的字节数 public class Test {public static void main(String[] args) throws IOException {DataOutputStream dataOutputStream new DataOutputStream(new FileOutputStream(D:\\a.txt));dataOutputStream.writeUTF(α);dataOutputStream.writeInt(1234567);dataOutputStream.writeBoolean(true);dataOutputStream.writeShort((short)123);dataOutputStream.writeLong((long)456);dataOutputStream.writeDouble(99.98);dataOutputStream.close();} } 2.10、Zip流 压缩文件 public class Test {public static void main(String[] args) throws IOException {File file new File(D:\\a.txt);FileInputStream fileInputStream new FileInputStream(file);File zip new File(D:\\a.zip);FileOutputStream fileOutputStream new FileOutputStream(zip);ZipOutputStream zipOutputStream new ZipOutputStream(fileOutputStream);int l 0;zipOutputStream.putNextEntry(new ZipEntry(file.getName()));while ((lfileInputStream.read())!-1){//压缩算法zipOutputStream.write(l);}fileInputStream.close();zipOutputStream.close();fileOutputStream.close();} } 解压文件 public class Test {public static void main(String[] args) throws IOException {File file new File(D:\\a.txt);File zip new File(D:\\a.zip);ZipFile zipFile new ZipFile(zip);ZipEntry entry zipFile.getEntry(a.txt);InputStream input zipFile.getInputStream(entry);FileOutputStream fileOutputStream new FileOutputStream(file);int l;while ((linput.read())!-1){//解压算法fileOutputStream.write(l);}fileOutputStream.close();input.close();} } 压缩多个文件 待补 解压多个文件 待补 2.11、Object流 想要使用ObjectOutputStream和ObjectInputStream对象一定要序列化 import java.io.Serializable;public class Person implements Serializable {private String name;private int age;public Person() {}public Person(String name, int age) {this.name name;this.age age;}public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}Overridepublic String toString() {return Person{ name name \ , age age };} } 当我们使用Serializable接口实现序列化操作的时候如果一个对象的某一个属性不想被序列化保存下来那么我们可以使用transient关键字进行说明 private transient String name; 2.11.1、ObjectOutputStream public class Test {public static void main(String[] args) throws IOException {File file new File(D:\\a.txt);ObjectOutputStream objectOutputStream new ObjectOutputStream(new FileOutputStream(file));objectOutputStream.writeObject(new Person(zhangsan,20));objectOutputStream.close();} } 2.11.2、ObjectInputStream public class Test {public static void main(String[] args) throws IOException, ClassNotFoundException {File file new File(D:\\a.txt);ObjectInputStream objectInputStream new ObjectInputStream(new FileInputStream(file));Person person (Person) objectInputStream.readObject();System.out.println(person);} } 2.12、RandomAccessFile 方法声明功能介绍public RandomAccessFile(String name, String mode)根据参数指定的名称和模式构造对象 r: 以只读方式打开 rw打开以便读取和写入 rwd:打开以便读取和写入同步文件内容的更新 rws:打开以便读取和写入同步文件内容和元数据 的更新int read()读取单个字节的数据void seek(long pos)用于设置从此文件的开头开始测量的文件指针偏移量void write(int b)将参数指定的单个字节写入void close()用于关闭流并释放有关的资源 public class Test {public static void main(String[] args) throws IOException {RandomAccessFile r new RandomAccessFile(D:\\a.txt, rw);r.seek(1);System.out.println((char) r.read());r.write(b);r.close();} }

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

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

相关文章

12380网站建设情况报告网站总体规划设计说明

hive分区重命名后,新的分区的分区大小为0 , 例如 alter table entersv.ods_t_test partition(dt2022-11-08) rename to partition(dt2022-11-21) ods_t_test 的2022-11-21分区大小为0。怎样修复 使用 msck repair table 命令来修复表的元数据,让hive重新…

太极 - MKT

太极 环境 下雨 下午 卧室 附上音乐 (沙石头 鱼儿 本身不也是物质的一部分么,都在不同的层次适应存在。 石头在河里打磨成圆滑,在沙漠变成啥子,这么看好像都是被动的过程。 但本质沙子石头都是原子层面的硅原子在…

佛山营销网站旅游网站建设方案后台

0-1背包理论基础 基础 DP数组与其下标的含义 dp[i][j],i为物品编号,j为背包容量 dp[i][j]表示从下标为[0-i]的物品里任意取,放进容量为j的背包,价值总和最大是多少。 递推公式 分类:是否要放入下标为i的物品&…

网站建设人员职责分布昌吉网站建设咨询电话

一、智能家居与会议系统 智能家居与会议系统分论坛将于3月28日同期举办! 智能会议系统它通过先进的技术手段,提高了会议效率,降低了沟通成本,提升了参会者的会议体验。对于现代企业、政府机构和学术界是不可或缺的。在这里&#x…

题解:P12410 「知りたくなかった、失うのなら」

草 -我ら不会と算に时む复なりlink 说在前面 如果你看了这个东西你最好就看个乐子别真的去写,卡常卡死你。 做法什么的请直接看正文。 注意到其他题解给出了很优美的做法,那么我就来点不优美的。 先设几个数字吧,设…

unity面向组合开发二:EC的代码实践

一、ECCore 需要在Unity项目中使用插件:UniRx,通过UniRx代替Mono的Update,Mono下做轮询性能消耗会有点大。 EntityMono代码:using System; using System.Collections.Generic; using EC; using UniRx; using Unity…

《咳咳,未来编程大师,顶尖程序员的第一条博客》

Helloooooo World!本人目前是一个在校大二的学生,正在备战蓝桥杯,希望有相同目标的朋友联系我,我们可以一起备赛,一起刷题。我的目标是在2026蓝桥杯比赛上拿下国一,哈哈哈哈虽然听起来很扯,但是我是会用拿国一的…

CSP-JF36

CSP-JF36T2 B. 最小的公倍数小题 ((10^L / 210) + 1) * 210 就是最小值#include <bits/stdc++.h> using namespace std;int n; int main(){// for(int i = 2; i <= 18; i++){ // long long x = pow…

airsim多无人机+无人车联合仿真辅导 - 教程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

超越炒作:使用Agentic AI构建系统架构

本文深入探讨了Agentic AI系统的架构设计,分享了实际应用中的模式、反模式和用例,讨论了如何管理这些分布式系统的复杂性和非确定性,并提供了构建可信赖、可扩展生产系统的实用建议。超越炒作:使用Agentic AI构建系…

河北省建设信息网站seo网站优化平台

12.全排列II 题目描述 给定一个可包含重复数字的序列 nums &#xff0c;按任意顺序 返回所有不重复的全排列。 示例 1&#xff1a; 输入&#xff1a;nums [1,1,2] 输出&#xff1a; [[1,1,2],[1,2,1],[2,1,1]]示例 2&#xff1a; 输入&#xff1a;nums [1,2,3] 输出&…

一个网站的建站流程建设安全协会网站

【题目来源】https://leetcode.cn/problems/valid-parenthesis-string/description/【题目描述】 给你一个只包含三种字符的字符串&#xff0c;支持的字符类型分别是 (、) 和 *。请你检验这个字符串是否为有效字符串&#xff0c;如果是有效字符串返回 true 。 有效字符串符合如…

岷县城乡建设局网站wordpress有多大的数据量

欢迎同步关注公众号【逆向通信猿】 远程声控系统技术报告 一、题目要求 实现一个远程声音控制系统。首先采集不同的语音指示信号,进行适当压缩;然后通过噪声信道实现远程传输,远端接收后再通过适当计算识别出是何指示,最后送入一个处于未知状态、但能控/能观的控制系统,…

【进入便捷的系统不解决问题】ubuntu开机出现‘系统出错且无法恢复。请联系系统管理员’

【进入便捷的系统不解决问题】ubuntu开机出现‘系统出错且无法恢复。请联系系统管理员’2025-10-03 17:09 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important;…

K个节点的组内逆序调整

K个节点的组内逆序调整题目 给定一个单链表的头节点head,和一个正数k实现k个节点的小组内部逆序,如果最后一组不够k个就不调整 例子: 调整前:1->2->3->4->5->6->7->8,k=3 调整后:3->2-&…

【任务】自然语言处理——情感分析 <上>

【任务】自然语言处理——情感分析 <上>pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "…

2025华为 OD 机试2025C卷 机考真题库清单(全真题库)含考点说明(OD上机考试2025年C卷) - 教程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

网站开发 职业环境分析重庆免费做网站

数据库 mysql面试题目&#xff1a; MySQL InnoDB、Mysaim的特点&#xff1f; 乐观锁和悲观锁的区别&#xff1f;&#xff1f; 行锁和表锁的区别&#xff1f; 数据库隔离级别是什么&#xff1f;有什么作用&#xff1f; MySQL主备同步的基本原理。 如何优化数据库性能&#…

做seo的网站推广咨询公司名称大全

1.前提是必须先安装好MySQL数据库(Mac下安装MySQL数据库见前一篇)2.安装Navicat3.点击navicate左上角&#xff1a;连接->MySQL->先测链接下&#xff0c;如果提示连接成功&#xff0c;就可以填写连接名&#xff0c;点击连接即可。双击刚创建的连接下面会有四个数据库用naV…

【Azure App Service】Root CA on App Service

应用服务具有受信任的根证书列表,无法在应用服务的多租户 Windows (App Service for Windows)中修改这些证书,但可以在应用服务环境 (ASE) 的受信任根存储中加载自己的证书颁发机构 (CA) 证书,这是因为ASE中的应…