wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Problem in deleting the file..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in deleting the file....." Watch "Problem in deleting the file....." New topic
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: http://aspose.com/file-tools
 
subject: Problem in deleting the file.....
 
Similar Threads
files are not delete
Trouble writing to a text file
User Defined Objects
Copying files
Problem in deleting the file.....