Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JGraph
>
Tutorial
> Download file as stream
Download file as stream.
import java.io.FileOutputStream; import java.io.InputStream; import com.independentsoft.graph.GraphClient; import com.independentsoft.graph.GraphException; import com.independentsoft.graph.files.DriveId; public class Console { public static void main(String[] args) { try { GraphClient client = new GraphClient(); client.setClientId("63333333-209e-454e-b7bd-55a4d201270f"); client.setTenant("independentsoft.onmicrosoft.com"); client.setClientSecret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); try(InputStream inputStream = client.getDriveItemAsStream("/Folder1/Test.pdf", new DriveId("b!T7ZW_FMzJ02x_G6HteZHZ"))) { try (FileOutputStream outputStream = new FileOutputStream("e:\\Test-download.pdf")) { byte[] buffer = new byte[1024]; int bytesRead = inputStream.read(buffer, 0, buffer.length); while (bytesRead > 0) { outputStream.write(buffer, 0, bytesRead); bytesRead = inputStream.read(buffer, 0, buffer.length); } } } } catch (GraphException e) { System.out.println(e.getCode()); System.out.println(e.getMessage()); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*