English 中文(简体)
贾瓦:下载总是 st。
原标题:Java: Download always stalls

几天前,我陷入一个严重问题,给我一个头痛:

所有瓦 Java基工具(Eclipse、Maven、AndrewSDK装载机......)都存在下载某些档案的问题:下载只是随意停留。

我已在Superuser上描述了我的问题,但没有人能够帮助我解决我的问题。 因此,我开始做一些测试,最后在问题结束时采用样本代码。

令人感兴趣的部分是,缓冲区的规模对这个问题的影响不大。 如果我把缓冲面积减少到1024,则大多数情况下的下载都是完整的。

该法典是否只给我的视窗系统造成问题?

阐明: 我不想与 Java一道制定下载方案,因此,确定样本代码无助于我,而守则只是证明问题。

public static void main(String[] args) {
    try {
        URL url = new URL("http://mirror.netcologne.de/maven2/com/google/android/android/2.3.3/android-2.3.3.jar");

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        InputStream in = conn.getInputStream();
        byte[] buffer = new byte[10485760]; // 10MiB
        long read = 0;
        while (true) {
            int bytes = in.read(buffer, 0, buffer.length);
            if (bytes < 0)
                break;
            read += bytes;
            System.out.println("Bytes read: " + read);
        }
        conn.disconnect();
        System.out.println("Finished");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
最佳回答

你面临的问题是 Java7造成的,细节是,使IPv6比IPv4更加优先。

This problem affects all Java based software but only occurs on some computers (may depend on the used Internet connection and/or local network components like switches, router...)

你可以将其改为IPv4,因为该系统在Java 6中被使用,方法是确定系统财产java.net.preferIPv4Stack=true

Setting this property is different for each application. For Eclipse you have to set it in the eclipse.ini.

对于Andoird SDK经理来说,你必须把文件toolsandroid.bat <>>>,并在档案接近尾声的 Java中添加“参数”<代码>-Djava.net.preferIPv4Stack=true

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签