downloading .zip from a link

im trying to download a .zip file from a link "http://pack.lavender-mc.com" it works just fine from browser but doesnt in terminal and in java
downloadUsingNIO("http://pack.lavender-mc.com", "C://Users//lordo//Desktop//test.zip");

private void downloadUsingNIO(String urlStr, String file) throws IOException {
URL url = new URL(urlStr);
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
downloadUsingNIO("http://pack.lavender-mc.com", "C://Users//lordo//Desktop//test.zip");

private void downloadUsingNIO(String urlStr, String file) throws IOException {
URL url = new URL(urlStr);
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
when i try to download from terminal i get the stuff in picture btw this link works "https://www.dropbox.com/scl/fi/hdpannlxcks044f6g8bw9/lmc_pack.zip?rlkey=9zc8bukx6ixrrbjl9payliv5f&dl=1"
Dropbox
lmc_pack.zip
Shared with Dropbox
No description
No description
11 Replies
JavaBot
JavaBot14mo ago
This post has been reserved for your question.
Hey @MoonSouhayl! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
szatkus
szatkus14mo ago
The url returns 301, so my guess it that openStream doesn't support redirections.
szatkus
szatkus14mo ago
That method is really old and clunky. In modern Java you this https://www.baeldung.com/java-9-http-client
Baeldung
Exploring the New HTTP Client in Java | Baeldung
Explore the new Java HttpClient API which provides a lot of flexibility and powerful features.
szatkus
szatkus14mo ago
Lol, actually it seems that you can fix it by adding "s" to "http" (https://pack.lavender-mc.com/).
MoonSouhayl
MoonSouhaylOP14mo ago
its stuck like this
No description
MoonSouhayl
MoonSouhaylOP14mo ago
wait let me try in java
szatkus
szatkus14mo ago
Oh, the site doesn't support HTTPS at all, so it won't work. Time to learn HttpClient. Good luck!
MoonSouhayl
MoonSouhaylOP14mo ago
eeeeh, do i reallly have to change it ? its working well and that page is full of stuff, my brain is fried :boohoo:
szatkus
szatkus14mo ago
Get some rest then.
MoonSouhayl
MoonSouhaylOP14mo ago
NO but do i really have to change it ? why would i ?
JavaBot
JavaBot14mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?