我使用这类来上传HTTP中的文件,我的问题是,当我从路由器中删除lan电缆时,上传块作为写调用块出现,下面显示了它的确切位置,我尝试中断线程,但这也没有帮助。
现在的问题是我如何打断outputStream?
public void addFilePart(String fieldName, File uploadFile)
throws IOException {
...
//removed code from here for clarity.
//Can be found in the link above
FileInputStream inputStream = new FileInputStream(uploadFile);
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1) {
//The code stuck here.
//using if (Thread.interrupted()) doesn't help
//as the write blocks when the network cable
//removed from the router
outputStream.write(buffer, 0, bytesRead);
}
outputStream.flush();
inputStream.close();
writer.append(LINE_FEED);
writer.flush();
}发布于 2015-04-01 20:41:12
到目前为止,我找到的最好的解决方案是从另一个线程执行HttpURLConnection.disconnect(),这似乎很好。
https://stackoverflow.com/questions/29358373
复制相似问题