从java中的服务器下载文件

编程入门 行业动态 更新时间:2024-10-24 16:22:40
本文介绍了从java中的服务器下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的java应用程序中,我使用以下方法从服务器下载文件。

In my java application I am using the following method to download files from server.

public void kitapJar(){ File f = new File("C:/PubApp_2.0/update/lib/kitap.jar"); try{ URL kitap = new URL("example/update/PubApp_2.0.jar"); org.apachemons.io.FileUtils.copyURLToFile(kitap, f); } catch(IOException ex){ System.out.println("Error...!!");} } }

但是这个下载速度非常慢。如何让它快速?

But this download is very slow. How can i make it fast ?

推荐答案

为什么在这么多程序员如此快地添加第三方库依赖于他们的代码?

Why on earth are so many programmers so fast in adding 3rd party library dependencies to their code?

try( ReadableByteChannel in=Channels.newChannel( new URL("example/update/PubApp_2.0.jar").openStream()); FileChannel out=new FileOutputStream( "C:/PubApp_2.0/update/lib/kitap.jar").getChannel() ) { out.transferFrom(in, 0, Long.MAX_VALUE); }

此代码将URL内容传输到没有任何第三方库的文件。如果它仍然很慢,你知道这不是额外的图书馆,也不是Java的错误。至少这里没有什么可以改善的。那么你应该搜索JVM之外的原因。

This code transfers a URL content to a file without any 3rd party library. If it’s still slow, you know that it is not the additional library’s and most probably not Java’s fault. At least there’s nothing you could improve here. So then you should search the reason outside the JVM.

更多推荐

从java中的服务器下载文件

本文发布于:2023-05-28 06:53:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315073.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   文件   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!