Java 实例 - 获取远程文件大小

Java 教程 · 2019-02-11 20:42:42

以下实例演示了如何获取远程文件的大小:

Main.java 文件

import java.net.URL; import java.net.URLConnection; public class Main { public static void main(String[] args) throws Exception { int size; URL url = new URL("http://www.codercto.com/wp-content/themes/codercto/assets/img/newlogo.png"); URLConnection conn = url.openConnection(); size = conn.getContentLength(); if (size < 0) System.out.println("无法获取文件大小。"); else System.out.println("文件大小为:" + size + " bytes"); conn.getInputStream().close(); } }

以上代码运行输出结果为:

文件大小为:4261 bytes

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Rapid Web Applications with TurboGears

Rapid Web Applications with TurboGears

Mark Ramm、Kevin Dangoor、Gigi Sayfan / Prentice Hall PTR / 2006-11-07 / USD 44.99

"Dear PHP, It's over between us. You can keep the kitchen sink, but I want my MVC. With TurboGears, I was able to shed the most heinous FileMaker Pro legacy 'solu-tion' imaginable. It has relationshi......一起来看看 《Rapid Web Applications with TurboGears》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

SHA 加密
SHA 加密

SHA 加密工具