社区
Java SE
帖子详情
怎么取InputStream里的数据到String? 不知道长度,无法read(byte[]),求其他方法
sisn
2004-01-08 01:43:47
怎么取InputStream里的数据到String? 不知道长度,无法read(byte[]),求其他方法..
...全文
152
5
打赏
收藏
怎么取InputStream里的数据到String? 不知道长度,无法read(byte[]),求其他方法
怎么取InputStream里的数据到String? 不知道长度,无法read(byte[]),求其他方法..
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
sisn
2004-01-08
打赏
举报
回复
解决了,自己看了一下文档.
正如jonkeyjohns(JonkeyJohns) 所说的:
InputStream有一个available()方法返回长度
这么怪的名字,不看文档谁知道是干嘛用的...
要是起个 length,size之类的名字就好了,文档都不用查 :)
fdw
2004-01-08
打赏
举报
回复
new String时用readcount限制一下。上面的错了
fdw
2004-01-08
打赏
举报
回复
int readcount = 0;
byte buffer[] = new byte[1024];
StringBuffer strbuffer = new StringBuffer;
while( ( readcount = InputStream.read(buffer) ) != -1 ) {
strbuffer.append( new String(buffer) );
}
strbuffer.toString();
什么文件都行,数据库的大对象也行
bluesmile979
2004-01-08
打赏
举报
回复
BufferedReader dis = new BufferedReader(new InputStreamReader(inputStream()));
String str = null;
StringBuffer sb = new StringBuffer;
while( (str = dis.readLine()) != null ){
sb.append( str );
}
sb.toString();
jonkeyjohns
2004-01-08
打赏
举报
回复
InputStream应该有一个available()方法返回长度
JavaIO流精讲上
课程内容主要有:File类概述、File类功能讲解、JAVA IO流概述、字节流、字符流、缓冲流、
InputStream
、OutputStream、
Read
er、Writer、File
InputStream
、FileOutputStream、
InputStream
Read
er、OutputStreamWriter、...
Byte
String
与
inputStream
互转
网上没搜到,记录一下
Byte
String
是protobuf的
byte
s类型生成后对应的java类型
Byte
String
fileStream = request.getFileStream();
byte
[]
byte
s = fileStream.to
Byte
Array();
Byte
Array
InputStream
byte
Array
InputStream
=...
InputStream
.
read
([
byte
[])详解
InputStream
.
read
([
byte
[])每次读
取
byte
[]数组大小的字节量,返回实质读
取
文件中的字节的
长度
,当读
取
字节流无任何文件内容后,返回值为-1。 // 字节流对象读
取
文件内容
InputStream
in = new InputStram(inPath);
byte
[] b =
byte
[10]; int len = 0; while((len = in.
read
(b)) != -1) /*
read
每次读
取
10个字节,返回读
取
长度
,当读
取
不满10个字节时, 返回实际读
取
字节数;当实际读
InputStream
中
read
()与
read
(
byte
[] b)
Zip
InputStream
中批量进行读
取
read
(
byte
[] b),比
read
()读
取
速度更快
InputStream
read
()
方法
详解
在Java7中,
InputStream
被定义为一个抽象类,相应的,该类下的
read
()
方法
也是一个抽象
方法
,这也就意味着必须有一个类继承
InputStream
并且实现这个
read
方法
。 查阅Java7 API,我们可以看到,在
InputStream
中定义了三个重载的
read
()
方法
: 但是在这三个
方法
中,只有参数列表为空的
read
方法
定义为抽象
方法
,这也就意味着在直接继承自InputStre
Java SE
62,614
社区成员
307,327
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章