wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes why cannot delete 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 » Sockets and Internet Protocols
Bookmark "why cannot delete file" Watch "why cannot delete file" New topic

why cannot delete file


Joined: Dec 02, 2003
Posts: 10
Dear all,
My problem here is after I ran my code, I cant delete the origin file that I have ftp it. For example, I ftp C:\a\a.txt to /home/kwwong/upload/a.txt. After doing this, I need to delete C:\a\a.txt but I got this message "Cannot delete a.txt:It is being used by another person or program".
Anyone knows what wrong with my code here?
Any helps are appreciated. Thank you very much.
BufferedReader reader = null;
Ftp ftp = null;
String tmp = null;
InetAddress Inet = null;
String lStrUploadFileLog = "C:/FTPLog/FTPLog_05122003.log";
String lStrUploadFilePath = "/home/kwwong/upload/";
String lStrFTP_USER = "kwwong";
String lStrFTP_PWD = "password";
String lStrFTP_IP = "";
String lStrLogFileDate= "LOG_FILE_DATE";
reader = new BufferedReader(new FileReader(new File(lStrUploadFileLog)));
Inet = InetAddress.getByName(lStrFTP_IP);
tmp = reader.readLine();
ftp = new Ftp(Inet,lStrFTP_USER,lStrFTP_PWD);

if(tmp != null){
System.out.println("lStrUploadFileLog = "+lStrUploadFileLog);
System.out.println("lStrUploadFilePath+lStrLogFileDate = "+(lStrUploadFilePath+lStrLogFileDate));
System.out.println("tmp = "+tmp);
StringTokenizer strtmp = new StringTokenizer(tmp,",");
int size_strtmp = strtmp.countTokens();

while (size_strtmp>0){
String lStrUploadFile = strtmp.nextToken();
StringTokenizer strlStrUploadFile = new StringTokenizer(lStrUploadFile,"\\");
int size_strlStrUploadFile = strlStrUploadFile.countTokens();
String substr = lStrUploadFile.substring(lStrUploadFile.lastIndexOf("\\")+1,lStrUploadFile.length());


System.out.println("File(s) download completed!");
try {
File ff = new File(lStrUploadFileLog);
boolean state = ff.delete();
} catch ( SecurityException se ) {
System.out.println("Error SecurityException: "+se );
catch(Exception e){
System.out.println("Error Exception1: "+e );
System.out.println("Upload to server completed!!!");
}catch(Exception e){

System.out.println("Error Exception: "+e);
if(reader != null)
if(ftp != null)
reader= null;
ftp= null;
tmp = null;
Inet = null;
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Perhaps a thread in your app isn't ending and/or releasing a file as you're hoping it will. I don't know. But the folks over in the Sockets and Internet Protocols forum, just might have an idea. So, I'm moving this thread...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

There's really not enough information here to answer your question. Where's this class "Ftp" that actually sends the file? If there's an issue with file descriptors being left open, it's presumably in there, since the code you're showing never opens that file. The code you're showing actually has little to do with actually sending the file -- it does a whole bunch of hard-to-follow stuff that's totally irrelevant to what we're talking about.

[Jess in Action][AskingGoodQuestions]

Joined: Dec 02, 2003
Posts: 10
Thanks for replying.
I agree. Here's the link: http://aspose.com/file-tools
subject: why cannot delete file
Similar Threads
why cannot delete file
files are not delete
Why cannot delete the file?
why cannot delete file
File transfering from client machine to Server through FTP.