Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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
android应用程序连接到google drive并将文件下载到sd卡_Android_Google Drive Api_Android Sdcard - Fatal编程技术网

android应用程序连接到google drive并将文件下载到sd卡

android应用程序连接到google drive并将文件下载到sd卡,android,google-drive-api,android-sdcard,Android,Google Drive Api,Android Sdcard,我的android应用程序连接到google drive并检查驱动器上的文件,如果文件不存在,则将其下载到SD卡。下面的代码不支持下载。 出现的问题是下载的文件在下载后显示0字节。请帮我找到代码中的错误。谢谢你的帮助 private void savefile(String filename, InputStream in , Boolean replace ) { try { java.io.File f = new java.io.File(fi

我的android应用程序连接到google drive并检查驱动器上的文件,如果文件不存在,则将其下载到SD卡。下面的代码不支持下载。 出现的问题是下载的文件在下载后显示0字节。请帮我找到代码中的错误。谢谢你的帮助

private void savefile(String filename, InputStream in , Boolean replace ) {  
    try {         
        java.io.File f = new java.io.File(filename);
        logonscreen("trying to savefile :"+filename);

        if(replace) {
            showToast("replace:"+replace.toString());

            OutputStream stream = new BufferedOutputStream(new FileOutputStream(filename)); 
            int bufferSize = 1024;
            byte[] buffer = new byte[bufferSize];
            int len = 0;
            while ((len = in.read(buffer)) != -1) {
                stream.write(buffer, 0, len);
            }
            if(stream!=null) {
                stream.close();
            }

        } else {
            showToast("replace: "+replace.toString()+" , file exists " + f.exists());

            if(f.exists()== false) {
                OutputStream stream = new BufferedOutputStream(new FileOutputStream(filename)); 
                int bufferSize = 1024;
                byte[] buffer = new byte[bufferSize];
                int len = 0;
                while ((len = in.read(buffer)) != -1) {
                    stream.write(buffer, 0, len);
                }
                if(stream!=null) {
                    stream.close();
                }
            }
        }
        //Do something    
    } catch (IOException e) {
        // TODO: handle exception
        logonscreen("exception at Save File:" +filename + "exception" + e.getMessage());
        //  showToast("exception:" + e.getMessage());
    } catch (Exception e) {
        logonscreen("exception at Save File:" + e.getMessage());
        //  showToast("exception:" + e.getMessage());
        e.printStackTrace();
    }

}

是否已检查您是否具有写入SD卡的正确权限?如果内存不足,请检查logcatErrors@Vannen是,包括权限@logcat不显示任何内存不足errors@prem未显示任何内存不足问题