我正在尝试创建一个Android应用程序,能够将PDF文件上传和下载到服务器,我已经在我的代码中包含了一种方法,可以从URL(例如“http://www.aaaa.com/myfile.pdf”)下载PDF并使用意图显示它。
但是我想知道是否有一种方法将Pdf编码为字节数组,反之亦然,将字节数组解码为PDF文件(我正在使用mongoDB)
谢谢大家 :)
import java.nio.file.*;
Path pdfFilePath = Paths.get("/file/path/your_file.pdf");
// Read file to byte array
byte[] pdfByteArray = Files.readAllBytes(pdfFilePath );
// Write byte array to file
Files.write(pdfFilePath , pdfByteArray);