我正在尝试使用以下代码删除网络(y驱动器)驱动器上的文件
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();
}
}
}
文件正在被上面的程序删除,但是这个程序没有使用用户名和密码,因为如果我输入了错误的凭证,那么仍然是文件正在删除
请建议采用这种或另一种方式来实现这一要求
提前谢谢。