当前位置:网站首页>IO流总结
IO流总结
2022-06-29 09:29:00 【linsa_pursuer】
//InputStream(字节流、输入流)Reader(字符流、输入流)OutputStream(字节流、输出流)Writer(字符流、输出流)
//InputStream-FilterInputStream(BufferedInputStream(缓冲字节输入流)、DataInputStream、LineNumberInputStream(过时)、PushbackInputStream)、
//ByteArrayInputStream(字节数组输入流)、FileInputStream(文件输入流)、ObjectInputStream(对象输入流)、PipedInputStream、SequenceInputStream、StringBufferInputStream(过时)
//OutputStream-FilterOutputStream(BufferedOutputStream(缓冲字节输出流)、DataOutputStream、PrintStream)、
//ByteArrayOutputStream(字节数组输出流)、FileOutputStream(文件输出流)、ObjectOutputStream(对象输出流)、PipedOutputStream
//Reader-BufferedReader(缓冲字符输入流)(LineNumberReader)、CharArrayReader、InputStreamReader(字符输入流)(FileReader)、FilterReader(PushbackReader)、PipedReader、StringReader
//Writer-BufferedWriter、CharArrayWriter、OutputStreamWriter(字符输出流)(FileWriter)、FilterWriter、PipedWriter、PrintWriter(缓冲字符输出流)、StringWriter
//文件操作
File file = new File("."+File.separator+"test.txt");//文件、目录("demo"、"a"+File.separator+"b")
boolean hasFile = file.exists();//判断当前File表示的文件或目录是否真实存在
boolean isFile = file.isFile();//判断当前File表示的是否为一个文件
boolean isDirectory = file.isDirectory();//判断当前File表示的是否为一个目录
File[] subs = file.listFiles();//获取当前目录中的所有子项
file.createNewFile();//创建该文件
file.delete();//删除文件或目录
file.mkdir();//创建目录
file.mkdirs();//创建多级目录
String name = file.getName();
long length = file.length();
boolean canRead =file.canRead();//可读
boolean canWrite =file.canWrite();//可写
boolean isHidden = file.isHidden();//是否为隐藏文件
RandomAccessFile raf = new RandomAccessFile("raf.dat","rw");//rw读写,r读
raf.write(1);//单字节、多字节write(data,0,len)
int rafInt = raf.read();//若返回值为-1表示读取到了文件末尾
raf.close();
//输入流
FileInputStream fis = new FileInputStream("osw.txt");//文件输入流
byte[] data = new byte[300];
int len = fis.read(data);
String fisStr = new String(data,0,len,"utf-8");
fis.close();
InputStreamReader isr = new InputStreamReader(fis,"utf-8");//字符输入流
int isrInt = isr.read();//-1表示不存在,用StringBuilder拼接(append((char)d))转为String
isr.close();
ObjectInputStream ois = new ObjectInputStream(fis);//对象输入流-对象必须实现Serializable接口
ois.readObject();
ois.close();
BufferedInputStream bis = new BufferedInputStream(fis);//缓冲字节输入流,提高读取效率
int bisInt = bis.read();//-1表示不存在
bis.close();
BufferedReader br = new BufferedReader(isr);//缓冲字符输入流
br.readLine();//读取一行数据
br.close();
//输出流
FileOutputStream fos = new FileOutputStream("osw.txt");//文件输出流(覆盖写模式、追加写模式-"fos.txt",true)
fos.close();
fos.write("hello".getBytes("utf-8"));
OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8");//字符输出流
osw.write("hello");
osw.close();
ObjectOutputStream oos = new ObjectOutputStream(fos);//对象输出流-对象必须实现Serializable接口
oos.writeObject("hello");
oos.close();
BufferedOutputStream bos = new BufferedOutputStream(fos);//缓冲字节输出流
bos.write(1);
bos.flush();
bos.close();
PrintWriter pw = new PrintWriter(osw);//缓冲字符输出流
pw.println("hello");
pw.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();//字节数组输出流
baos.write(data, 0, len);
byte[] buffer = baos.toByteArray();边栏推荐
- Implementation of iequalitycomparer interface in C #
- 2019.11.3 learning summary
- Call another interface button through win32API
- 這個開源項目超哇塞,手寫照片在線生成
- 解决zxing的QR码包含中文时乱码的问题
- Downloading and installing VMware (basic idea + detailed process)
- C语言库函数--strstr()
- 智能组卷系统设计
- L2-3 is this a binary search tree- The explanation is wonderful
- 1021 deep root (25 points)
猜你喜欢

C#窗体向另一个窗体实时传值

打印100~200之间的素数(C语言)

Related problems of pointer array, array pointer and parameter passing

Fully understand the volatile keyword

云主机端口扫描

Call another interface button through win32API

Voir le classement des blogs pour csdn

《CLR via C#》读书笔记-单实例应用程序

September 29, 2020 non commodity templating code level rapidjson Library

Dev使用过程中的基本操作
随机推荐
C#中IEqualityComparer接口的实现
Analysis on the specific execution process of an insert statement in MySQL 8.0 (3)
HDU 4578 transformation (segment tree + skillful lazy tag placement)
SQL Server 数据库的连接查询
Arc view and arc viewpager
Web vulnerability manual detection and analysis
Wandering -- the last programming challenge
Acwing271 [teacher Yang's photographic arrangement] [linear DP]
智能组卷系统设计
Web漏洞手动检测分析
std::unique_ptr<T>与boost::scoped_ptr<T>的特殊性
查看CSDN的博客排名
2019.11.20 training summary
Power strings [KMP cycle section]
Contents of advanced mathematics
Common usage of LINQ in C #
BUUCTF--reverse2
Analyze in detail the PBOT mining virus family behavior and the principle of exploited vulnerabilities, and provide detailed protection suggestions for the blue army
IIS服务器相关错误
2019.10.6 training summary