Overhead and code speed (java.io.file array and java.lang.string array)
Just trying to sort out a small category I have here
At present, I am developing an application involving collecting the file list into memory for deletion Now, at this point, I think Java io. The file array may take up too much memory because the files list in this context may contain hundreds of possible entries
Instead of using the file object list to eat up too much memory, I think I collect the file name list and store them as Java Lang. string will be cheaper for memory Now, this is my question: remember which files are cheaper to delete:
>Store a file object instead of a string object and call delete(); Each in the loop (using too much memory). > Use the file name to store the array of string objects, but for each iteration of the loop, use the file name list to create a new file object and call delete(); On this file (which means that a new file object is created and destroyed each time the loop iterates – possibly using too much processor power)
I want to make the program as fast as possible, so any method has its advantages. I just want to see which methods have the least overhead Thank you in advance!
Solution
java. io. File represents the file name information / metadata of entries in the file system, which does not contain the contents of the file
In other words, code like the new file ("somelarge. TXT") will not Txt file is loaded into memory
The only real data contained in each file object is the string path of the file (and transient int prefixlength) – it is considered that the file class is just a wrapper that knows how to call the string path of all file system operations
In addition to other requirements, the best choice here is the easiest to read code and best convey your intention