本地/远程查找文件大小

发布于 2024-12-16 02:14:13 字数 161 浏览 3 评论 0原文

我正在编写一个程序来查找文件的文件大小。

在java中可以吗?

在 PHP 中我知道有一个 filesize()。

另一种选择是在 unix 中使用 ab http:// 但它如何与 java 集成?

您认为解决此问题的最佳/最有效方法是什么?

I'm writing a program to find the file size of files.

Is it possible in java?

In PHP I know there is a filesize().

Another alternative was using ab http:// in unix but how is it integratabtle with java?

What do you think is the best/most efficient way to attack this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白昼 2024-12-23 02:14:13

您可以使用 java Runtime 来执行命令并从缓冲区读取输出并显示它。

        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec("ab http://whatever ");
        // read the stream into the buffer and display the results.

如果您本地有该文件,则可以使用 File.length()

You can use java Runtime to execute the command and read the output from the buffer and display it.

        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec("ab http://whatever ");
        // read the stream into the buffer and display the results.

If you have the file locally, then you can use File.length()

心意如水 2024-12-23 02:14:13

检索页面,提取链接,然后仅请求每个 uri 的标头。

PHP 中的 filesize() 可能比较冒险,因为是否允许您在远程文件上使用它完全取决于主机的配置。您可能会考虑使用curl代替

使用shell中的curl,例如,在我写下以下内容时查看页面右侧的广告:

 curl -I http://static.adzerk.net/Advertisers/180414077f314dbdbaa8d8e2f7898249.gif

...产量,除其他外:

Content-Type: image/gif
Content-Length: 17798

...这可能就是您正在寻找的内容为了。在 PHP 中,使用 CURLOPT_NOBODY 获得等效内容

Retrieve a page, extract links, and then only request the header for each uri.

filesize() in PHP may be dicey, as whether or not you're allowed to use it on a remote file will be entirely up to the configuration of your host. You might consider curl instead

Using curl from a shell, for instance, to look at an ad on the rhs of the page as I write this:

 curl -I http://static.adzerk.net/Advertisers/180414077f314dbdbaa8d8e2f7898249.gif

...yields, among other things:

Content-Type: image/gif
Content-Length: 17798

...which may be what you're looking for. Within PHP, get the equivalent with CURLOPT_NOBODY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文