Stacked Q&A

How to save Google Drive download outpustream to a file?
  • 3 voting
  • 2022-06-26 00:00

    I want to download a file from my Google Drive Account and save it on my computer.

    String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
    OutputStream outputStream = new ByteArrayOutputStream();
    service.files().get(fileId).executeMediaAndDownloadTo(outputStream);
    

    I don't know how to handle the outpustream so I can export it to a file. The code I am using is from Google Drive APIs.

  • 0 1489 0 0
첨부 파일
답변
총 0개의 답변이있습니다.
  • 답변일: 2022-06-26 00:00

    The code you have now gets the stream you just need to save it as a file.

    OutputStream out = new FileOutputStream("fileName");
    
    DriveFiles.Get request = drive.files().get(fileId);
    request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());
    request.executeMediaAndDownloadTo(out);
    

    You should be checking the documentation for the Google APIs Java client library Resumable Media Downloads.

  • 0 0 채택된 답변 퍼블 채택!
Tages
    활동순위
    유저
      파트너사