当前位置:网站首页>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 :
边栏推荐
- HAC cluster modifying administrator user password
- Microblogging hot search stock selection strategy
- Select knowledge points of structure
- 【torch】|torch.nn.utils.clip_grad_norm_
- Pix2pix: image to image conversion using conditional countermeasure networks
- Mysql高级篇学习总结9:创建索引、删除索引、降序索引、隐藏索引
- Configuration file converted from Excel to Lua
- Nacos TC setup of highly available Seata (02)
- 【华为机试真题详解】统计射击比赛成绩
- Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
猜你喜欢
Review of double pointer problems
[untitled]
Steady, 35K, byte business data analysis post
[leetcode daily question] number of enclaves
[mask requirements of OSPF and Isis in multi access network]
剑指 Offer II 039. 直方图最大矩形面积
【LeetCode】18、四数之和
Vulhub vulnerability recurrence 71_ Unomi
Summary of deep learning tuning tricks
CUDA11.1在线安装
随机推荐
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
SQLite queries the maximum value and returns the whole row of data
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Improve jpopup to realize dynamic control disable
Three methods of Oracle two table Association update
【云原生】3.1 Kubernetes平台安装KubeSpher
【LeetCode】18、四数之和
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
SQLite add index
Huawei equipment is configured with OSPF and BFD linkage
Vite configures the development environment and production environment
趋势前沿 | 达摩院语音 AI 最新技术大全
Questions d'examen écrit classiques du pointeur
Idea one key guide package
February 12 relativelayout
Pickle and savez_ Compressed compressed volume comparison
Qt TCP 分包粘包的解决方法
Safe mode on Windows
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index