当前位置:网站首页>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();
}
}
}
}
边栏推荐
- Laravel8 authentication login
- 38. appearance series
- Halcon uses points to fit a plane
- Is the individual industrial and commercial door a legal person enterprise
- 62. the last number left in the circle
- 【长时间序列预测】Aotoformer 代码详解之[4]自相关机制
- week7
- Introduction to redis high availability
- 什么是工程预付款
- 57 - II. Continuous positive sequence with sum s
猜你喜欢

WebRTC AEC 流程解析

分公司负责人需要承担的法律责任
![[grpc development] go language builds simple server and client](/img/24/06c3c1219ecad7e117f4df152e9ce7.jpg)
[grpc development] go language builds simple server and client

Matlab: halftone and dither conversion

Performance test - Analysis of performance test results

个人申请OV类型SSL证书

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

Conversion of Halcon 3D depth map to 3D image
![[long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation](/img/12/27531fc791b3f49306385831309c5e.png)
[long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation

Word frequency statistics using Jieba database
随机推荐
59 - I. maximum value of sliding window
57 - II. Continuous positive sequence with sum s
Redis cache data consistency and problems
Stack and queue classic interview questions
Matlab: image rotation and interpolation and comparison of MSE before and after
Greenplum【问题 05】Greenplum Streaming Server自定义客户端问题处理(不断增加ing)
C language - how to define arrays
Deep understanding of asynchronous programming
[road of system analyst] collection of wrong topics in software engineering chapters
XML parameter schema, the same MTK SW version is compatible with two different sets of audio parameters
16. 最接近的三數之和
个体工商户是不是法人企业
Lldp protocol
Go 接口实现原理【高阶篇】
公司注册认缴资金多久
Introduction to sringmvc
Simple introduction to key Wizard
网络加速谁更猛?CDN领域再现新王者
Matlab: halftone and dither conversion
Select gb28181, RTSP or RTMP for data push?