Search code examples
box-api

Box: How to download a file to a specific folder?


I'm using java sdk provided by box and I saw in the documentation, how to download a file:

String fileID = "11111";
BoxFile file = new BoxFile(api, fileID);
BoxFile.Info info = file.getInfo();

FileOutputStream stream = new FileOutputStream(info.getName());
file.download(stream);
stream.close();

I'm able to download it, but it's putting everything inside my project structure and I want to give a specific path so I can get all my outputs there.


Solution

  • the BoxFile documentation does not provide an attribute for the file path, where to store the downloaded file.

    But the API for the FileOutPutStream is providing a solution for this:

    new FileOutputStream("this/path/to/my/file.txt");
    

    You can find all possible values for the constructor of this class under https://docs.oracle.com/javase/8/docs/api/?java/io/FileOutputStream.html