当前位置:网站首页>The InputStream stream has been closed, but the file or folder cannot be deleted, indicating that it is occupied by the JVM
The InputStream stream has been closed, but the file or folder cannot be deleted, indicating that it is occupied by the JVM
2022-06-25 23:45:00 【langmeng110】
Sometimes liumingming is closed , But you still can't delete files or folders , Prompt by JVM Occupation, etc
public void download(String sourceUrl, String targetPathFile) {
URL url = null;
// Download a picture from the Internet
InputStream inputStream = null;
OutputStream outputStream = null;
// Set up a network link
HttpURLConnection con = null;
try {
url = new URL(sourceUrl);
con = (HttpURLConnection) url.openConnection();
inputStream = con.getInputStream();
outputStream = new FileOutputStream(new File(targetPathFile));
int n = -1;
byte b[] = new byte[1024];
while ((n = inputStream.read(b)) != -1) {
outputStream.write(b, 0, n);
}
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(inputStream!=null)
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if(outputStream!=null)
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}In such a time , This can usually be done :
System.gc();// Call garbage collection before deleting , such jvm It won't occupy the file
try {
Thread.sleep(100);// This is my side , If you don't sleep for a while , Still unable to delete
} catch (InterruptedException e) {
e.printStackTrace();
}
boolean dirFile = FileUtils.deleteQuietly(new File(targetDirPath));
boolean zipFile = FileUtils.deleteQuietly(new File(targetZipPathFile));
边栏推荐
- OpenResty篇01-入门简介和安装配置
- php进程间传递文件描述符
- 解析產品開發失敗的5個根本原因
- String object (constant) pool
- 关于go中资源泄漏/goroutine泄漏/内存泄漏/CPU打满等情况分析
- Customize the qcombobox drop-down box, right align the display, and slide the drop-down list
- 第五章 习题(124、678、15、19、22)【微机原理】【习题】
- DPVS-FullNAT模式keepalived篇
- When are the three tools used for interface testing?
- Use of xinchida ble 5.0 Low Power Bluetooth module (at command serial port transparent transmission) rsbrs02abr
猜你喜欢
随机推荐
解决TypeError: Unicode-objects must be encoded before hashing
平衡二叉树AVL
Customize the qcombobox drop-down box, right align the display, and slide the drop-down list
Uniapp -- the use of document collation and push of unipush
idea 查看单元测试覆盖率
Audio basics and PCM to WAV
xtrabackup的备份还原
The package name of the manifest file in the library project and the app project are not the same
CXF
如何进行流程创新,以最经济的方式提升产品体验?
二叉排序树
php中使用google protobuf协议环境配置
Kylin
CSDN原力值
C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
Analysis on resource leakage /goroutine leakage / memory leakage /cpu full in go
Online customer service - charging standards and service provision of third parties
Binary, hexadecimal, big end and small end
C2. k-LCM (hard version)-Codeforces Round #708 (Div. 2)
QT custom implemented calendar control









