我正在使用谷歌硬盘开发应用程序,我可以使用这些应用程序查看我的文件。我想下载文件,但我不能。 这是我的功能,等于谷歌文档:
非常感谢!
/* Download a file's content.
*
* @param service Drive API service instance.
* @param file Drive File instance.
*
* @return InputStream containing the file's content if successful, {@code null} otherwise.
*/
public static InputStream downloadFile(Drive service, File file) throws IOException
{
if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0)
{
try
{
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
return resp.getContent();
}
catch (IOException e)
{
// An error occurred.
e.printStackTrace();
return null;
}
}
else
{
// The file doesn't have any content stored on Drive.
return null;
}
}
Logcat没有错误,但我没有在下载,SD卡等中看到任何文件
如果没有错误,我必须在SD卡,系统等中看到非常小心吗?
它还有什么必要吗?
答案 0 :(得分:1)
您正在获取文件内容并返回InputStream
但是您的代码未显示您正在使用此InputStream
执行的操作。您需要使用它来将文件的内容保存到磁盘或数据库等...请查看FaddishWorm在评论中发送给您的链接,该文件将文件写入SD卡:{{3} }