I am trying to delete a file on network (y drive) drive using below code
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.UserAuthenticator;
import org.apache.commons.vfs.auth.StaticUserAuthenticator;
import org.apache.commons.vfs.impl.DefaultFileSystemConfigBuilder;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.FileObject;
public class DeleteLogFile {
public static void main(String[] args) {
String filePath = "y:\\test\\test.log";
String domain = "ABCDESDX";
String userName = "abc";
String password = "xyzl@jun2013";
String remoteFilePath = filePath;
try {
UserAuthenticator auth = new StaticUserAuthenticator(domain, userName, password);
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileObject fo = VFS.getManager().resolveFile(remoteFilePath, opts);
if (fo.exists()) {
System.out.println("FILE IS THERE");
if (fo.delete()) {
System.out.println("deleted");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
file is deleting by above program but this program are not using username and password because if I putting wrong credential then still file is deleting
PLEASE SUGGEST ON THIS or alternative way to achieve this requirement
thanks in advance.