问题
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?
回答1:
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.
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.
EDIT: I don't guarantee anything, but you could also try to disconnect() and then connect() again. Never tried it, see if it works.
回答2:
By default there is no way. If you really want this feature, you have write some code for that. Write a URLHandler which gives a socket wrapper, that does buffering. Implement reset methods() as you like.
Thanks, Ramesh
来源:https://stackoverflow.com/questions/5807340/how-to-reset-urlconnection-in-java