how to delete file?

Discussions

General J2EE: how to delete file?

  1. how to delete file? (4 messages)

    hello
    i use "sun.net.ftp" package to read and save files hosted in a ftp server,now,i can "get" and "put" files to ftp server,but i can't find the "delete" method in the "FtpClient" client,if after i read a file,i want to delete it,how can i do?
    thank you!

    Threaded Messages (4)

  2. Re: how to delete file?[ Go to top ]

    After you "get" the file from ftp server, you should know where the file is located on your file system. Hence, you can create a java.io.File object and use the delete() method to delete the file. This method would return a boolean to indicate if the file deletion was successfully or not.
  3. Re: how to delete file?[ Go to top ]

    no,you misunderstand me,i want to delete the file from ftp server.
  4. Re: how to delete file?[ Go to top ]

    Since java.io.File class has a constructor which takes URI as the parameter, you can create an instance with something like "ftp://ftp.example.com/uri" and then use the same old delete() method afterwards.
  5. FTPClient ftp = new FTPClient(); ftp.connect(ftpHost); ftp.login( ftpUser, ftpPWD ); //Returns true on successful login ftp.deleteFile(filePath); //Returns true on successful delete