java代码中postman下载zip,没有类型
时间: 2023-11-08 17:49:36 浏览: 92
A级景区数据文件json
您好,您可以尝试以下Java代码来下载Zip文件:
```java
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
public class DownloadZip {
public static void main(String[] args) throws IOException {
String fileUrl = "https://example.com/your-zip-file.zip";
String saveDir = "D:/downloads/"; // 下载文件保存的目录
URL url = new URL(fileUrl);
URLConnection connection = url.openConnection();
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
FileOutputStream fileOutputStream = new FileOutputStream(saveDir + "your-zip-file.zip");
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
fileOutputStream.close();
in.close();
System.out.println("Zip file downloaded successfully.");
}
}
```
您需要将 `fileUrl` 替换为您要下载的Zip文件的URL,将 `saveDir` 替换为您想要将Zip文件保存的目录。运行此代码,它将从给定的URL下载Zip文件并将其保存到指定的目录中。
阅读全文