gpt4 book ai didi

java - 输入流超时

转载 作者:行者123 更新时间:2023-12-02 00:10:26 25 4
gpt4 key购买 nike

有没有办法为输入流设置超时?

我当前的代码如下所示:

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");

最佳答案

我认为根据您的要求,您可以使用

HttpURLConnection.setReadTimeout()

也许这些链接会对您有所帮助。

  1. Is it possible to read from a Java InputStream with a timeout?
  2. Class HttpURLConnection
  3. Can I set a timeout for a InputStream's read() function?

关于java - 输入流超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12914484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com