Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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 一些手机可以';不能在android中从url(POST)下载pdf_Java_Android - Fatal编程技术网

Java 一些手机可以';不能在android中从url(POST)下载pdf

Java 一些手机可以';不能在android中从url(POST)下载pdf,java,android,Java,Android,从流下载文件(url responce)我尝试不使用手机。但不使用某些手机,文件创建时没有写入。 我正在更改字节[4096],字节[1024]…,同样的错误也会发生 请给我一个建议 public void saveToDisk(ResponseBody body, String pdfFileName, String module_type, String test_name) { try { File sdcard_destinationFile; if

从流下载文件(url responce)我尝试不使用手机。但不使用某些手机,文件创建时没有写入。 我正在更改字节[4096],字节[1024]…,同样的错误也会发生 请给我一个建议

public void saveToDisk(ResponseBody body, String pdfFileName, String module_type, String test_name) {
    try {
        File sdcard_destinationFile;
        if (module_type.equalsIgnoreCase("ADD")) {

            sdcard_destinationFile = new File(Environment.getExternalStorageDirectory()
                    + "/download/" + pdfFileName + "_" + test_name + ".pdf");
        } else {
            sdcard_destinationFile = new File(Environment.getExternalStorageDirectory()
                    + "/download/" + pdfFileName + ".pdf");
        }


        InputStream is = null;
        OutputStream os = null;

        try {
            Log.e("file",body+"");
            is = body.byteStream();
            os = new FileOutputStream(sdcard_destinationFile);
            byte data[] = new byte[4096];
            int count;
            int progress = 0;
            while ((count = is.read(data)) != -1) {
                os.write(data, 0, count);
                progress += count;
                Log.d(TAG, "Progress: " + progress + "/" + body.contentLength() + " >>>> " + (float) progress / body.contentLength());
            }
            Log.d("aaaaa", "Progress: " + progress + "/" + body.contentLength() + " >>>> " + (float) progress / body.contentLength());
            os.flush();
            Log.e("isis",is +"");
            Log.e("isis",os +"");
            if (is != null) is.close();
            if (os != null) os.close();
            Log.d(TAG, "File saved successfully!");
         showPdf(pdfFileName, module_type, test_name);
           return;
        } catch (IOException e) {
            e.printStackTrace();
            Log.d(TAG, "Failed to save the file!");
            return;
        } finally {

        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.d(TAG, "Failed to save the file!");
        return;
    }
}

请放入堆栈跟踪。我在代码中找不到任何错误。您需要为处理多个设备添加特定于版本的代码。请尝试使用多设备兼容的文件下载程序。您可以尝试使用GitHubi附加图像上提供的TestTube库,您现在可以检查,同一个文件的工作移动内存分配为30 KB,但听说同一个文件仅57 BI,用于下载文件,易于使用,无需处理字节流。谢谢ADM我使用了DownloadManger,我遇到一些错误