如何在java中重置URLConnection? [英] How to reset URLConnection in java?

查看:182
本文介绍了如何在java中重置URLConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法重置连接,以便我可以从文件的开头读取?
这是一个缓慢的过程,重新连接到sarting读取,我想通过http每秒读取一次文件20次,还有其他方法吗?

is there any way to reset the connection,so that i can read from starting of the document? It is a slow process that reconnecting to read from sarting,i want to read a file 20 times per second through http,is there any other way to do this?

推荐答案

URLConnection是一个简单但有点愚蠢的课程。我建议你用Java方式做:实例化一个新的URLConnection。 ;)
Java实际上并不是一种能够重新组合对象的语言。

URLConnection is an easy but somewhat "dumb" class. I can suggest you to do it the Java way: instantiate a new URLConnection. ;) Java is not really a language that encorages reusage of objects.

您可以尝试重置输入流,请参阅 docs 了解更多信息,但我不知道认为它会做另一个GET。谁知道URLConnections的InputStream和OutputStream背后的具体实现是如何完成的。

You can try resetting the input stream, see the docs for more info, but I don't think it will do another GET. Who knows how the concrete implementation behind InputStream and OutputStream of URLConnections is done.

编辑:我不保证任何东西,但你也可以尝试断开()然后再次连接()。从未尝试过,看看它是否有效。

I don't guarantee anything, but you could also try to disconnect() and then connect() again. Never tried it, see if it works.

这篇关于如何在java中重置URLConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆