这个读文件为什么不可以呢?
来源:互联网 发布:淘宝店铺装修软件大全 编辑:程序博客网 时间:2024/04/30 17:53
项目中有个读Stream的问题,我用了最原始的办法,发现当InputStream中是xml可以读出,当是其他的时候就不可以了。虽然后来有了其他方案解决了,但是还是不知道原因,这里贴出来,想知道大家的看法,谢谢.
try {
Assert.notNull(file);
InputStream in = file.getFileContent().getInputStream();
List<Byte> cache = new ArrayList<Byte>();
byte data = (byte) in.read();
while (data != -1) {
cache.add(data);
data = (byte) in.read();
}
if (in != null) {
in.close();
}
byte[] cache2 = new byte[cache.size()];
for (int i = 0; i < cache.size(); i++) {
cache2[i] = cache.get(i);
}
System.out.println("cache2: " + cache2.length);
output.write(cache2);
} finally {
if (output != null) {
output.close();
}
}
===>>
try {
Assert.notNull(file);
InputStream in = file.getFileContent().getInputStream();
byte[] cache2 = new byte[in.available()];
in.read(cache2);
output.write(cache2);
if (in != null) {
in.close();
}
} finally {
if (output != null) {
output.close();
}
}
- 这个读文件为什么不可以呢?
- 信息可以量化,灵魂为什么就不可以呢?
- 可以的阿,为什么就不可以呢?甚至还可以设置背景图片呢
- 为什么写这个博客呢。。。。
- 为什么博客不可以粘贴?》
- 做个什么不可以呢
- 百度为什么喜欢CSDN这个博客呢
- 为什么要引入filebuf这个对象呢?
- 百度为什么要有这个点击原理呢
- 有些JS为什么不可以单独放在一个js文件里面
- 为什么不可以缺了static?
- 为什么中断上下文不可以休眠
- 为什么中断上下文不可以休眠
- jQuery 赋值attr()为什么不可以
- js为什么不可以相互继承?
- 为什么不能把这个斜线省略掉呢?
- 为什么会有jsessionid,这个东东有什么用呢?
- [求助] 这个简单的程序为什么没有预期效果呢?
- 相关研究组、个人主页链接
- 数学之美系列二十一 - 布隆过滤器(Bloom Filter)
- 绑定IP和MAC地址
- RCP启动速度慢问题的解决
- 支持msnp15协议python可发送离线消息脚本附录2
- 这个读文件为什么不可以呢?
- 支持msnp15协议python可发送离线消息脚本
- UML 九种基本的模型图
- 相关会议列表
- sql子查询语句
- MySql Query Brower 1.2.15
- javascript常用小例子
- oracle10G的"企业管理器"
- Socket编程相关数据类型定义(抄袭)