This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19761|Reply: 1

[Source] Java byte[] and InputStream are converted to each other

[Copy link]
Posted on 8/12/2021 10:58:43 AM | | |
1:byte[] to InputStream
InputStream sbs = new ByteArrayInputStream(byte[] buf);

2: InputStream to InputStreambyte[]
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100]; buff is used to store temporary data read in loops
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in_b = swapStream.toByteArray(); in_b is the result after the conversion

The code is as follows:

Copy the stream stream code

Original address:The hyperlink login is visible.




Previous:.NET/C# attributes CallerMemberName, CallerFilePath, CallerLineNumber
Next:OpenSSL is deployed from visa documents to IIS and SLB
 Landlord| Posted on 8/13/2021 11:45:20 AM |
hutool flow operation

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com