当前位置:网站首页>IO system - code example
IO system - code example
2022-06-12 05:43:00 【Python's path to becoming a God】
public class StreamDemo4 {
public static void main(String[] args) {
InputStream inputStream = null;
try {
inputStream = new FileInputStream("abc.txt");
int length = 0;
// Add a buffer to read , Each time the data is added to the buffer , When the buffer is full , once Read , Instead of reading every byte
byte[] buffer = new byte[1024];
while((length = inputStream.read(buffer,5,5))!=-1){
System.out.println(new String(buffer,5,length));
}
// int read = inputStream.read();
// System.out.println((char)read);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class CopyFile {
public static void main(String[] args) {
// Define source data file
File src = new File("abc.txt");
// Define destination data file
File dest = new File("aaa.txt");
// Create an input stream object
InputStream inputStream = null;
// Create an output stream object
OutputStream outputStream = null;
try {
inputStream = new FileInputStream(src);
outputStream = new FileOutputStream(dest);
// Input and output mode with cache
byte[] buffer = new byte[1024];
int length = 0;
// Complete the process of data transmission
while((length = inputStream.read(buffer))!=-1){
outputStream.write(buffer);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/** * The character stream can read Chinese characters directly , Chinese garbled code will appear when processing byte stream */
public class ReaderDemo3 {
public static void main(String[] args) {
Reader reader = null;
try {
reader = new FileReader("abc.txt");
int length = 0;
char[] chars = new char[1024];
// Add buffer
while((length = reader.read(chars))!=-1){
System.out.println(new String(chars,0,length));
}
// int read = reader.read();
// System.out.println((char)read);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class WriterDemo {
public static void main(String[] args) {
File file = new File("writer.txt");
Writer writer = null;
try {
writer = new FileWriter(file);
writer.write("www.mashibing.com");
writer.write(" Write something about it ");
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
边栏推荐
- Simple introduction to key Wizard
- [fastapi] use pycharm to configure and use environment variables for fastapi projects
- 62. the last number left in the circle
- 【js小知识】轻松了解js防抖与节流
- RTMP streaming +rtmp playback low delay solution in unity environment
- [daily question on niuke.com] two point search
- 37. serialized binary tree
- [speech] how to customize ring back tone according to different countries
- 分公司负责人需要承担的法律责任
- [untitled]
猜你喜欢

Halcon uses points to fit a plane

Beginning is an excellent emlog theme v3.1, which supports emlog Pro

beginning一款非常优秀的emlog主题v3.1,支持Emlog Pro

16. Somme des trois plus proches

什么是工程预付款

Role and understanding of proc/cmdline

Nature | 给全球的新冠伤亡算一笔账

Stack and queue classic interview questions

16. sum of the nearest three numbers

数据集成框架SeaTunnel学习笔记
随机推荐
Is the individual industrial and commercial door a legal person enterprise
March 4, 2021
虚函数与纯虚函数的关系
Caused by: org. h2.jdbc. JdbcSQLSyntaxErrorException: Table “USER“ already exists; SQL statement:
Date ()
Reverse linked list
个人申请OV类型SSL证书
Conversion of Halcon 3D depth map to 3D image
Test work summary - performance test related issues
Thesis reading_ Figure neural network gin
Word frequency statistics using Jieba database
Matlab: halftone and dither conversion
WiFi protocol and ieee905 protocol learning details
UBI details and JFFS2 square FS UBIFS
[machine learning] first day of introduction
深入理解异步编程
[gin] gin framework for golang web development
DMA RDMA technology details
16. 最接近的三数之和
Tkinter uses webview2 web component (sequel)