import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; public class FileDownloader { public static void main(String[] args) { String fileUrl = "http://example.com/files/sample.pdf"; String savePath = "/path/to/save/sample.pdf"; try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpGet request = new HttpGet(fileUrl); try (CloseableHttpResponse response = httpClient.execute(request)) { response.getEntity().writeTo(new FileOutputStream(savePath)); System.out.println("File downloaded successfully."); } } catch (IOException e) { e.printStackTrace(); } } } protocol = P2P port = 8080


上一篇:
下一篇:
切换中文