当前位置:网站首页>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 :
边栏推荐
- Simple understanding of interpreters and compilers
- Configuration file converted from Excel to Lua
- Vulhub vulnerability recurrence 71_ Unomi
- [untitled]
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- Huawei equipment is configured with OSPF and BFD linkage
- Nacos - TC Construction of High available seata (02)
- Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
- Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
- Excel转换为Lua的配置文件
猜你喜欢
Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
注释、接续、转义等符号
RT thread analysis log system RT_ Kprintf analysis
Notes, continuation, escape and other symbols
C进阶-数据的存储(上)
Check the useful photo lossless magnification software on Apple computer
Configuration file converted from Excel to Lua
Imperial cms7.5 imitation "D9 download station" software application download website source code
03. Login of development blog project
02. Develop data storage of blog project
随机推荐
C# AES对字符串进行加密
Nacos TC setup of highly available Seata (02)
Note the various data set acquisition methods of jvxetable
Please wait while Jenkins is getting ready to work
2022 half year summary
nacos-高可用seata之TC搭建(02)
Codeforces Round #804 (Div. 2) Editorial(A-B)
Deep learning -yolov5 introduction to actual combat click data set training
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
Safe mode on Windows
自建DNS服务器,客户端打开网页慢,解决办法
Cuda11.1 online installation
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
Hometown 20 years later (primary school exercises)
Solution of QT TCP packet sticking
Configuration file converted from Excel to Lua
算法-- 爬楼梯(Kotlin)
【华为机试真题详解】统计射击比赛成绩
js Array 列表 实战使用总结
Modbus协议通信异常