有没有办法给InputStream设置超时时间?
我当前的代码是这样的:
public class DownloadFile implements Runnable {
private EventHandler eh;
private String source;
private String destination;
public void run(){
try {
Log.d("Download", "Download... " + source);
URL url = new URL(source);
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(destination + "t");发布于 2012-10-16 20:21:40
我认为对于你的需求,你可以使用
HttpURLConnection.setReadTimeout()请注意,这些链接将对您有所帮助。
发布于 2012-10-16 20:20:28
您也可以使用计时器,但我认为Handler解决方案是最优雅的。
看看这个:http://developer.android.com/reference/android/os/Handler.html
https://stackoverflow.com/questions/12914484
复制相似问题