java - 如何从远程服务器下载文件到本地
PHP中文网
PHP中文网 2017-04-18 09:07:37
0
1
236
比如说我有一个系统,这个系统会每天定点从另一个服务器端下载一个txt文件下来,请大神给条思路,我该用哪些API。刚步入IT的菜鸟不知如何下手
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Peter_Zhu

I have seen a friend write a small example using non-blocking I/O before, and I thought it was very cool:

URL website = new URL("http://下载地址");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("本地要存储的文件地址");//例如:test.txt
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

Although I haven’t tried it, it should be OK.

If it’s timed, it shouldn’t be hard to catch you, right? java.util.Timer should help you

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template