BufferedInputStream根本不读书?

时间:2014-09-26 13:18:17

标签: java bufferedinputstream

我正在学习BufferedInputStream,所以我尝试用它来下载文件...... 我试图使用read(byte [] b,int off,int len)来做它但是我注意到我的所有字节数组都等于0并且它没有读取任何东西......

URL url = new URL("http://download.freeapk.ru/uploads/com.whatsapp.apk");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(10000);
    int mStartByte = 0;
    String byteRange = 6000000 + "-" + 8000000;
    conn.setRequestProperty("Range", "bytes=" + byteRange);
    conn.connect();
    if (conn.getResponseCode() / 100 != 2) {
        System.out.println("error");
    }
    BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
    byte data[] = new byte[conn.getContentLength()];
    in.read(data, 0, 2000000);

对不起梅西码:3。

编辑:

URL url = new URL("http://download.freeapk.ru/uploads/com.whatsapp.apk");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(10000);
    int mStartByte = 0;
    String byteRange = 6000000 + "-" + 8000000;
    conn.setRequestProperty("Range", "bytes=" + byteRange);
    conn.connect();

    if (conn.getResponseCode() / 100 != 2) {
        System.out.println("error");
    }
    byte data[] = new byte[conn.getContentLength()];
    InputStream ins = conn.getInputStream();
    DataInputStream dis = new DataInputStream(ins);
    dis.read(data, mStartByte, 2000000);

还尝试了DataInputStream和全零。 :(

0 个答案:

没有答案