Java Resumble Downloader [закрыто]JAVA

Программисты JAVA общаются здесь
Anonymous
Java Resumble Downloader [закрыто]

Сообщение Anonymous »

Я видел код, который делает файл загрузки возобновлением, который работает, но я не знаю, когда код хочу проверить соединение, он проверяет только 206 и 200 кода ответа статуса, но почему мы просто проверяем код успеха? 2 **? < /p>
и 2-how

Код: Выделить всё

public class ResumableDownloader {

public static void download(String fileURL, String savePath) throws IOException {

File file = new File(savePath);
long existingFileSize = file.exists() ? file.length() : 0;

URL url = new URL(fileURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

// Set Range header to resume download
conn.setRequestProperty("Range", "bytes=" + existingFileSize + "-");

int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_PARTIAL || responseCode == HttpURLConnection.HTTP_OK) {
try (InputStream in = conn.getInputStream();
RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
System.out.println(existingFileSize);
raf.seek(existingFileSize); // Move to the end of existing file
byte[] buffer = new byte[4096];
int bytesRead;

while ((bytesRead = in.read(buffer)) != -1) {
raf.write(buffer, 0, bytesRead);
}

System.out.println("Download complete.");
}
} else {
System.out.println("Server does not support partial content. Response code: " + responseCode);
}

conn.disconnect();
}

public static void main(String[] args) throws IOException {
String fileURL = "https://pdn.sharezilla.ir/com.rar";
String savePath = "largefile.rar";
download(fileURL, savePath);
}
}
Мне интересно загрузить файл, используя сборку Java в API

Подробнее здесь: https://stackoverflow.com/questions/797 ... downloader

Вернуться в «JAVA»