首页 > 解决方案 > 如何在电报机器人(JAVA)中下载文件

问题描述

我想在我的电报机器人代码中下载一个文件,许多教程说我必须使用 getFile 方法,而我在 4.2 版本的电报 API 中找不到该方法,那么我如何将文件下载到主机 pc 中的特定目标?谢谢

标签: javaapifiledownloadtelegram

解决方案


Assuming you are using TelegramBot SDK from rubenlagus (https://github.com/rubenlagus/TelegramBots), as I faced same issue. Below is my solution.

GetFile getFile = new GetFile().setFileId(fileId);
String filePath = execute(getFile).getFilePath();
File file = downloadFile(filePath, outputFile);

推荐阅读