当前位置:网站首页>28io stream, byte output stream writes multiple bytes
28io stream, byte output stream writes multiple bytes
2022-07-06 05:26:00 【dengfengling999】
write() Yes 3 individual Write data to hard disk
write(byte[] b) take b.length Bytes from specified Of byte Array Write this output stream
public void' write(byte[] b): take b.length Byte writes this output stream from the specified byte array
If the first byte written is a positive number (0-127), Then the display will query ASCII surface
If the first byte written is negative , The first byte and the second byte will form a Chinese display , Query the system default code table (GBK)
write(byte[] b,int off,int len ) Writes the specified byte array to len Bytes , From the offset off Start the output stream to this
public void write(byte [] b,int off,int len): Write part of the byte array to a file
int off: Start index of array
int len: Write a few bytes
The specified byte array is written len byte , From the offset off Start output to this output stream
write(int b) Output the specified byte stream Write a byte
/*
Write character method : have access to String The methods in the class put the string , Convert to byte array
byte[] getByte() Convert string to byte array
*/
byte[] byte2=" Hello ".getBytes();
System.out.println(Arrays.toString(byte2));//[-28, -67, -96, -27, -91, -67] Coding format UTF-8 inside 3 A byte is a Chinese character ,JDK in 2 A byte is a Chinese character
fos.write(byte2);
Detailed code :
package demo28 Byte output stream writes multiple bytes ;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
public class DenoOutputStream {
public static void main(String[] args) throws IOException {
//1. Create a FileOutputStream object , The destination to which the data is to be written in the constructor
FileOutputStream fos=new FileOutputStream(new File("E:\\ Multithreading \\b.txt"));
//2. call FileOutputStream Object write Method to write data to a file
// Write in file 100, Need to write 3 Bytes
fos.write(49);
fos.write(48);
fos.write(48);
/*
public void' write(byte[] b): take b.length Byte writes this output stream from the specified byte array
If the first byte written is a positive number (0-127), Then the display will query ASCII surface
If the first byte written is negative , The first byte and the second byte will form a Chinese display , Query the system default code table (GBK)
*/
byte [] bytes={65,66,67,68,69};//ABCDE
byte [] bytess={-65,-66,-67,68,69};
//fos.write(bytess);// Grill E
fos.write(bytes);//ABCDE
/*
public void write(byte [] b,int off,int len): Write part of the byte array to a file
int off: Start index of array
int len: Write a few bytes
The specified byte array is written len byte , From the offset off Start output to this output stream
*/
fos.write(bytes,1,2);// Put a part of the array ,BC write in
/*
Write character method : have access to String The methods in the class put the string , Convert to byte array
byte[] getByte() Convert string to byte array
*/
byte[] byte2=" Hello ".getBytes();
System.out.println(Arrays.toString(byte2));//[-28, -67, -96, -27, -91, -67] Coding format UTF-8 inside 3 A byte is a Chinese character ,JDK in 2 A byte is a Chinese character
fos.write(byte2);
// Release resources
fos.close();
}
}
result : establish b.txt, Write data
At the beginning

After running the code :

边栏推荐
- ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
- 剑指 Offer II 039. 直方图最大矩形面积
- February 12 relativelayout
- 【华为机试真题详解】统计射击比赛成绩
- 【torch】|torch.nn.utils.clip_grad_norm_
- Hyperledger Fabric2. Some basic concepts of X (1)
- 毕业设计游戏商城
- UCF(暑期团队赛二)
- Modbus协议通信异常
- Idea one key guide package
猜你喜欢

Modbus protocol communication exception

Vulhub vulnerability recurrence 72_ uWSGI

Three methods of Oracle two table Association update

Golang -- TCP implements concurrency (server and client)

Figure database ongdb release v-1.0.3

02. Develop data storage of blog project

nacos-高可用seata之TC搭建(02)

Vulhub vulnerability recurrence 68_ ThinkPHP

03. 开发博客项目之登录

Idea one key guide package
随机推荐
flutter 实现一个有加载动画的按钮(loadingButton)
GAMES202-WebGL中shader的编译和连接(了解向)
jdbc使用call调用存储过程报错
Summary of deep learning tuning tricks
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
JS array list actual use summary
Driver development - hellowdm driver
Qt TCP 分包粘包的解决方法
First acquaintance with CDN
图数据库ONgDB Release v-1.0.3
Notes, continuation, escape and other symbols
Using stopwatch to count code time
[leetcode] 18. Sum of four numbers
Vulhub vulnerability recurrence 68_ ThinkPHP
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
Detailed summary of SQL injection
Some common skills on unity inspector are generally used for editor extension or others
MySQL if and ifnull use
Sword finger offer II 039 Maximum rectangular area of histogram
F12 solve the problem that web pages cannot be copied