远程url文件地址转成byte
2024-10-19 06:13:05
public static byte[] urlTobyte(String url) throws MalformedURLException {
URL ur = new URL(url);
BufferedInputStream in = null;
ByteArrayOutputStream out = null;
try {
in = new BufferedInputStream(ur.openStream());
out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
byte[] content = out.toByteArray();
return content;
}
最新文章
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
- css实现省略号
- 【BZOJ-3667】Rabin_Miller算法 随机化判素数
- jad 反编译java
- CAF(C++ actor framework)使用随笔(send sync_send)(二)
- 在Linux系统中修改IP地址
- R语言学习笔记之外部文件读取
- C++ STL之min_element()与max_element()(取容器中的最大最小值)
- light oj 1152 Hiding Gold
- Linux下创建软链接
- C语言中extern关键字的使用
- Python包中__init__.py作用
- 【HP-UNIX】修改HP-UNIX主机名称
- C++ 继承与派生
- eclipse:报错信息The superclass ";javax.servlet.http.HttpServlet"; was not found on the Java Build Path
- Python3 函数注解
- CentOS6.7的安装
- pymysql的使用心得(1)------小细节,注意!
- 【线段树】HDU 3397 Sequence operation 区间合并
- Spring在xml配置里配置事务