A
A
askalidov2022-03-29 17:35:25
Java
askalidov, 2022-03-29 17:35:25

Is it possible to download a pdf file using Java?

There is a button click handler that writes a specific pdf file (using the iText library). Is it possible to make it so that with the same click, this file is downloaded, for example, to the download folder?
To make it clearer, below is the code that downloads the file by url, you need to implement the same thing, but instead of url - the path to the finished pdf file.

URL website = new URL("https://africau.edu/images/default/sample.pdf");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("C:/Downloads/sample.pdf");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

Upd:
In short, what should happen in general: a button is pressed - it is formed (already implemented) and pdf is downloaded.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question