Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

removing lock on the file to delete.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am running into a problem after FTP the file. it wont delete it unless i close tomcat. i get the error that the file is being used. although i am closing the connection. here is the code.
public void upload(String remotedir, String file, String localdir, boolean asc) throws IOException {
//Check if file is OK
File ftpFile = new File(localdir + "\\" + file);
if (!ftpFile.isFile()) {
throw new IOException("FTP file does not exist.");
}
RandomAccessFile raf = new RandomAccessFile(ftpFile,"r");
ftpSetDir(remotedir);
ftpSetTransferType(asc);
dsock = ftpGetDataSock();
OutputStream os = dsock.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
ftpSendCmd("STOR "+file);
int idata = 0;
while (true) {
idata = raf.read();
if (idata != -1) {
dos.writeByte(idata);
} else {
break;
}

}
//System.err.println("Done creating a file");
dos.flush();
dos.close();
ftpLogout();
}

private void ftpLogout() {
try {
pos.print("BYE\r\n");
pos.flush();
pos.close();
dcis.close();
csock.close();
dsock.close();
} catch (IOException e) {
System.err.println("Error closing FTP: " + e.getMessage());
}
}
public void FTPConnect(String server, String user, String pass) {
try {
ftpConnect(server);
ftpLogin(user, pass);
//System.out.println("connection made");
} catch(IOException ioe) {
System.err.println("Failed with connection to Server");
}
}
I am connecting first, then i call the upload method then i delete the file...
any ideas would help please... thanx
reply
    Bookmark Topic Watch Topic
  • New Topic