Java Call Delete File method Delete file, but delete dirty

Source: Internet
Author: User

Scene:

A temporary folder is generated when the data is downloaded in the program. There are some TXT and other format files inside the clip.

After the data download, you need to delete this temporary folder, but always delete the dirty, there will always be a file residue.

The net found the cause of the problem:

Content from: u012102536 's Blog

Original address: http://blog.csdn.net/u012102536/article/details/53583455

Cause:    The temporary file object has not been dereferenced in the Java Virtual Machine (JVM), although it appears that there are no variables pointing to the temporary file object, but it is not yet urgent to be automatically reclaimed by the garbage collector to dereference.  Because the JVM also occupies a temporary file object, the deletion cannot succeed. Solution:   A garbage collection is performed before the file is deleted, releasing temporary file object references from the Java virtual machine.

   System.GC ();  //Perform a garbage collection   File.delete ();

Java Call Delete File method Delete file, but delete dirty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.