使用 Java 上传文件(带进度条) [英] File Upload with Java (with progress bar)
问题描述
我对 Java 非常陌生,并且大部分时间都在自学,所以我开始构建小程序.我想做一个可以从本地磁盘中选择一个文件并将其上传为 multipart/form-data POST 请求但带有进度条.显然,用户必须授予 Java 小程序访问硬盘驱动器的权限.现在我已经完成了第一部分的工作:用户可以使用 JFileChooser
对象选择一个文件,该对象方便地返回一个 File
对象.但我想知道接下来会发生什么.我知道 File.length()
会给我文件的总大小(以字节为单位),但是我如何将选定的 File
发送到网络,我该如何监控发送了多少字节?提前致谢.
I'm extremely new to Java, and have mostly just been teaching myself as I go, so I've started building an applet. I'd like to make one that can select a file from the local disk and upload it as a multipart/form-data POST request but with a progress bar. Obviously the user has to grant permission to the Java applet to access the hard drive. Now I've already got the first part working: the user can select a file using a JFileChooser
object, which conveniently returns a File
object. But I'm wondering what comes next. I know that File.length()
will give me the total size in bytes of the file, but how do I send the selected File
to the web, and how do I monitor how many bytes have been sent? Thanks in advance.
推荐答案
我最终偶然发现了一个开源 Java 上传器小程序,并在它的代码中找到了我需要知道的一切.以下是描述它的博客文章以及来源的链接:
I ended up stumbling across an open source Java uploader applet and found everything I needed to know within its code. Here are links to a blog post describing it as well as the source:
这篇关于使用 Java 上传文件(带进度条)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!