从一个URL下载原始数据,基于byte字节,得到byte数组
2015-11-25 10:07
387 查看
public static byte[] loadRawDataFromURL(String u) throws Exception { URL url = new URL(u); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); //缓存2KB final int BUFFER_SIZE = 2*1024; final int EOF = -1; int c; byte[] buf = new byte[BUFFER_SIZE]; while (true) { c = bis.read(buf); if (c == EOF) break; baos.write(buf, 0, c); } conn.disconnect(); is.close(); byte[] data = baos.toByteArray(); baos.flush(); return data; }
相关文章推荐
- 把文件的属性由隐藏改为存档
- andriod 开发环境问题总结
- C++对代码质量的要求更高
- Mybatis通用Mapper
- md5sum
- java 高性能代码优化
- websphere 7.0 堆内存设置
- Android百度地图导航的那些坑
- iOS开发 实现动画的暂停和继续播放
- AFNetworking源码解析<四>
- java clone 对象的深复制(深克隆)和浅复制(浅克隆)介绍
- [置顶] 注解学习之初始化布局及控件2
- asp.net类序列化生成xml文件实例详解
- liunx安装jdk冲突
- MyBatis 入门到精通(三) 高级结果映射
- 进度条制作
- 欢迎使用CSDN-markdown编辑器
- nankai100_2
- 基于Net-SNMP的Agent的开发和使用
- javascript获取transform中的属性值