Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.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 swing下载在windows xp中不起作用_Java_Swing - Fatal编程技术网

Java swing下载在windows xp中不起作用

Java swing下载在windows xp中不起作用,java,swing,Java,Swing,我有一个示例代码,可以从web及其swing应用程序下载一些数据(pdf、gif和mp3)。它在Windows 7中运行良好,但在Windows xp中不起作用 我的代码是 public static Float downloadFile(String targetUrl,File filePath) { try { Integer count=0; URL url

我有一个示例代码,可以从web及其swing应用程序下载一些数据(pdf、gif和mp3)。它在Windows 7中运行良好,但在Windows xp中不起作用

我的代码是

 public static Float downloadFile(String targetUrl,File filePath)
        {
            try
            {

                Integer count=0;
                URL url = new URL(targetUrl);
                HttpURLConnection connection=(HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.setDoOutput(true);
                connection.setConnectTimeout(10000);
                connection.connect();

                int lenghtOfFile = connection.getContentLength();
                Thread.sleep(100);
                InputStream input = new BufferedInputStream(url.openStream());
                Thread.sleep(100);
                OutputStream output = new FileOutputStream(filePath);
                byte data[] = new byte[input.available()];
                long total = 0;
                while ((count = input.read(data)) != -1)
                {
                    total += count;
                    output.write(data, 0, count);
                }
                output.flush();
                output.close();
                input.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            return 2.5f;
            }  
    }
通过将代码设置为0,它进入无限while循环。问:初始化缓冲区时,“input.available()”是什么?如果那一刻正好是“0”,你会很伤心


一种解决方案是使用固定长度的缓冲区(例如8192)。

两个系统是否安装了相同的JRE?睡觉是为了什么?