Is there a way to delete a specific file in Java?
-
I have a file I must delete. I looked at many tutorials but they didn't cover it. I have a file from which my program reads input and after reading I want to delete it. How do I do that? Is there a specific way you can do that in Java by naming the path of the file? I really don't know and I desperately need help.
-
Answer:
(new File("filename")).delete();
Ivan at Yahoo! Answers Visit the source
Other answers
import java.io.File; public class testdel { public static void main(String[] _init) { File thisfile = new File("C:\\Users\\Mike\\test.txt"); thisfile.delete(); } } Make sure you .close() the file after you are finished reading from it.
Michael
Related Q & A:
- How do I check a type is of a specific template?Best solution by Stack Overflow
- Is there a way to delete old bookmarks?Best solution by wikihow.com
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
- Is there a way to delete all your contacts at once on Windows Live Messenger?Best solution by pallareviews.com
- Is there a way to delete all your favorite videos on youtube?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.