• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why cannot delete file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
try{
String lStrUploadFileLog = "C:/FTPLog/FTPLog_05122003.log";
String lStrUploadFilePath = "/home/kwwong/upload/";
String lStrFTP_USER = "kwwong";
String lStrFTP_PWD = "password";
String lStrFTP_IP = "192.168.1.100";
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);
ftp.setType(ftp.BINARY);

if(tmp != null){
System.out.println("lStrUploadFileLog = "+lStrUploadFileLog);
System.out.println("lStrUploadFilePath+lStrLogFileDate = "+(lStrUploadFilePath+lStrLogFileDate));
ftp.startPut(lStrUploadFileLog,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();
size_strtmp--;
StringTokenizer strlStrUploadFile = new StringTokenizer(lStrUploadFile,"\\");
int size_strlStrUploadFile = strlStrUploadFile.countTokens();
String substr = lStrUploadFile.substring(lStrUploadFile.lastIndexOf("\\")+1,lStrUploadFile.length());

ftp.startPut(lStrUploadFile,lStrUploadFilePath+substr);
ftp.waitUntilTransferComplete();

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

System.out.println("Error Exception: "+e);
}
finally{
if(reader != null)
reader.close();
if(ftp != null)
ftp.close();
reader= null;
ftp= null;
tmp = null;
Inet = null;
}
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kent
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying.
reply
    Bookmark Topic Watch Topic
  • New Topic