小编mat*_*att的帖子

Java HttpUrlConnection实际发送的字节的状态

我为URLConnections的基本GET和POST请求实现了一个WebRequest类.

其中一个功能是提交文件 - 现在我想计算并显示上传文件的进度 - 但我不知道如何做到这一点:

    for (KeyFilePair p : files) {
        if (p.file != null && p.file.exists()) {
            output.writeBytes("--" + boundary + "\n");
            output.writeBytes("Content-Disposition: form-data; name=\""
                    + p.key + "\"; filename=\"" + p.file.getName() + "\"\n");
            output.writeBytes("Content-Type: " + p.mimetype
                    + "; charset=UTF-8\n");
            output.writeBytes("\n");

            InputStream is = null;
            try {
                long max = p.file.length();
                long cur = 0;
                is = new FileInputStream(p.file);
                int read = 0;
                byte buff[] = new byte[1024];
                while ((read = is.read(buff, 0, buff.length)) > 0) { …
Run Code Online (Sandbox Code Playgroud)

java upload outputstream status httpurlconnection

5
推荐指数
1
解决办法
1664
查看次数

标签 统计

httpurlconnection ×1

java ×1

outputstream ×1

status ×1

upload ×1