| Author |
Problem in deleting the file.....
|
Sachin Kumar Khandelwal
Greenhorn
Joined: Dec 02, 2003
Posts: 8
|
|
Hello, I'm writtent a class having method to create a file and delete the files within a directory. But it doesnot deletes the file which is created from the class where the deletion method is called . the files which are already present in that directory get deleted . i'm sending the code below. plz help me to solve the prob. as my work get stucked. thanks in advance... Sachin Code of Class ------------- import java.io.File; import java.io.FileWriter; // This Class has the methods used only for the tester classes. public class TestUtility { public TestUtility() { } public File createTestFile(String vFileName, String vFileContent) { File mTestFile = new File(vFileName); try { FileWriter fw = new FileWriter(mTestFile); fw.write(vFileContent); fw.close(); } catch(java.io.IOException e) { e.printStackTrace(); } return mTestFile ; } public void deleteFilesInFolder(String vDir) { File mDir = new File(vDir); File[] mFileList = mDir.listFiles(); for (int i=0;i<mFileList.length ;i++ ) { //mFileList[i].delete(); System.out.println("TestUtility :: mFileList[i] :: " + mFileList[i].toString()); System.out.println("TestUtility :: mFileList[i].delete() :: " + mFileList[i].delete()); } //Dleting the Empty Folder also. //mDir.delete(); } } and calling it from a method.. methodname() { TestUtility _TestUtility = new TestUtility() _TestUtility.createTestFile( _SrcDir + mCategory + ".xml", mTestString); _TestUtility.deleteFilesInFolder(_SrcDir); }
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
Please do not crosspost the same question in multiple forums. I'm closing this thread. You can continue this discussions at http://www.coderanch.com/t/372379/java/java/deleting-file Thank you
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Problem in deleting the file.....
|
|
|