字节数组输入流读取操作
生活随笔
收集整理的这篇文章主要介绍了
字节数组输入流读取操作
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
和文件的读取操作类似,不同的是构造函数中是用 byte[]来初始化 ByteArrayInputStream
package com.machuang.io.others;import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream;public class ByteArray {public static void main(String[] args) throws IOException {byteArrayRead();}public static void byteArrayRead() throws IOException {// 创造字节数组,(从服务器或者其他主机上传来的 byte[])String msg = "和文件读取操作一样"; byte[] msgBytes = msg.getBytes(); // 待读取的字节数组 InputStream bis = new BufferedInputStream( new ByteArrayInputStream(msgBytes) );// byteBufbyte[] byteBuf = new byte[1024];int len = 0;// 读取操作while(-1 != (len = bis.read(byteBuf))) {System.out.println(new String(byteBuf, 0, len));}bis.close();}}
转载于:https://www.cnblogs.com/cappuccinom/p/8821838.html
总结
以上是生活随笔为你收集整理的字节数组输入流读取操作的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: jquery对输入框内容的数字校验
- 下一篇: jQuery遇到问题的小记