Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何计算上传任务';s百分比_Java_Android_Upload_Progressdialog - Fatal编程技术网

Java 如何计算上传任务';s百分比

Java 如何计算上传任务';s百分比,java,android,upload,progressdialog,Java,Android,Upload,Progressdialog,我在UploadAsync类中有一个doFileUpload方法,它扩展了AsyncTask。 我想知道如何从以下代码计算上传任务的百分比,以使用publishProgress(“+值”)更新ProgressDialog 感谢我曾经遇到过类似的问题,我使用光标跟踪下载的字节,如下所述: 这就是我在应用程序中所做的 long total = 0; int lenghtOfFile=connection.getContentLength(); while ((count

我在
UploadAsync
类中有一个
doFileUpload
方法,它
扩展了AsyncTask
。 我想知道如何从以下代码计算上传任务的百分比,以使用
publishProgress(“+值”)更新
ProgressDialog


感谢

我曾经遇到过类似的问题,我使用光标跟踪下载的字节,如下所述:
这就是我在应用程序中所做的

 long total = 0;
 int lenghtOfFile=connection.getContentLength();

            while ((count = input.read(data)) != -1) {
                total += count;
                // publishing the progress....
                // After this onProgressUpdate will be called
                publishProgress(""+(int)((total*100)/lenghtOfFile));
                // writing data to file
                output.write(data, 0, count);
                if (isCancelled()) break;
            }

您可以在这里看到它:

here
HttpURLConnection=null
 long total = 0;
 int lenghtOfFile=connection.getContentLength();

            while ((count = input.read(data)) != -1) {
                total += count;
                // publishing the progress....
                // After this onProgressUpdate will be called
                publishProgress(""+(int)((total*100)/lenghtOfFile));
                // writing data to file
                output.write(data, 0, count);
                if (isCancelled()) break;
            }