how to write to java file in the best way?

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

Was this solution helpful to you?

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

Just Added Q & A:

Find solution

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.