int length = 0;
URL url;
try {
url = new URL(url1);
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
//根据响应获取文件大小
length = urlcon.getContentLength();
urlcon.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return length;
}
/**
-
从输入流中获取字节数组
-
@author Jayvee
-
@param inputStream
-
@return
-
@throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
/**
-
@author Jayvee
-
@Description: todo
*/
public static byte[] downLoadFromUrl(String urlStr) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] getData = readInputStream(inputStream);
return getData;
}
/**
-
@author Jayvee
-
@Description: todo
*/
public static byte[] readFromByteFile(String pathname) throws IOException {
File filename = new File(pathname);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename));
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
in.close();
byte[] content = out.toByteArray();
return content;
}
}
假设获取网络图片 http://pic.962.net/up/2018-1/2018191570320420.jpg 的大小和内容。
Java 代码:
try {
int fileSize = FileUtils.getFileLength(“http://pic.962.net/up/2018-1/2018191570320420.jpg”); // 获取文件大小
byte[] file = FileUtils.downLoadFromUrl(“http://pic.962.net/up/2018-1/2018191570320420.jpg”); // 获取文件内容
System.out.println(“文件大小:” + fileSize + " 字节");
System.out.println(“文件内容:” + file);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(资料价值较高,非无偿)
![img](https://img-blog.csdnimg.cn/img_convert/a7982f8eab233b82cd8e2733109af54b.jpeg)
总结
在清楚了各个大厂的面试重点之后,就能很好的提高你刷题以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门即可获取!
[外链图片转存中…(img-TcqUxUBy-1711628600875)]
[外链图片转存中…(img-iBhH8WIE-1711628600876)]
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门即可获取!