0

同様の質問を読みましたが、何もうまくいきません。問題は、メソッド getProgress() が非常に大きな値 ( 16300 など) を返すことです。何が間違っていましたか?

私のコードを見てください

 public void download()
{
    RandomAccessFile file = null;
    InputStream inputStream = null;
    HttpURLConnection connection = null;
    try
    {
        connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("GET");
        connection.setDoOutput(true);
        connection.connect();
        String connectLength = connection.getHeaderField("Content-Length");

        if(connectLength == null || Integer.parseInt(connectLength) < 1 || connectLength.equals(""))
            error();

        size = Long.parseLong(connectLength);
        file = new RandomAccessFile(filePath,"rw");
        inputStream = new BufferedInputStream(url.openStream());
        int read ;

        while((read = inputStream.read(buffer)) > 0 && status == States.DOWNLOADING)
        {
            file.write(buffer,0,read);
            downloadedS += read;
        }
    }
}
 public float getProgress()
    { 
        return ((float)downloadedS/size)*100;
    }
4

1 に答える 1