用Java进行文件上传(带进度条) [英] File Upload with Java (with progress bar)

查看:174
本文介绍了用Java进行文件上传(带进度条)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Java来说,我是非常新的,大多数时候我只是在自学,所以我开始构建一个小程序。我想创建一个可以从本地磁盘选择一个文件,并将其上传为multipart / form-data POST请求,但是带有进度条。显然,用户必须授予Java applet访问硬盘驱动器的权限。现在我已经得到了第一部分的工作:用户可以使用 JFileChooser 对象来选择一个文件,它可以方便的返回一个 File 对象。但是我想知道接下来会发生什么。我知道 File.length()会给我文件的总大小(以字节为单位),但是如何发送选定的 File 到网络,我如何监视已经发送了多少字节?感谢提前。

解决方案

我最终绊倒了一个开源的Java上传器小程序,发现了我需要知道的一切。这里有链接到一个博客文章,描述它以及来源:

Article

rel =noreferrer / p>

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.

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:

Article
Source Code

这篇关于用Java进行文件上传(带进度条)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆