List of usage examples for org.apache.commons.vfs2 FileObject delete
boolean delete() throws FileSystemException;
From source file:sftpexamples.SftpUtility.java
/** * Method to delete the specified file from the remote system * * @param hostName HostName of the server * @param username UserName to login//from w w w . ja v a 2 s .c o m * @param password Password to login * @param localFilePath LocalFilePath. Should contain the entire local file * path - Directory and Filename with \\ as separator * @param remoteFilePath remoteFilePath. Should contain the entire remote * file path - Directory and Filename with / as separator */ public static void delete(String hostName, String username, String password, String remoteFilePath) { StandardFileSystemManager manager = new StandardFileSystemManager(); try { manager.init(); // Create remote object FileObject remoteFile = manager.resolveFile( createConnectionString(hostName, username, password, remoteFilePath), createDefaultOptions()); if (remoteFile.exists()) { remoteFile.delete(); System.out.println("Delete remote file success"); } } catch (Exception e) { throw new RuntimeException(e); } finally { manager.close(); } }