package com.eiq;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.Selectors;
import org.apache.commons.vfs.UserAuthenticator;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.auth.StaticUserAuthenticator;
import org.apache.commons.vfs.impl.DefaultFileSystemConfigBuilder;
public class RemoteFileDemo {
public static void main(String[] args) throws IOException {
String domain="hyd\\all";
String userName="chiranjeevir";
String password="Acvsl@jun2013";
String remoteFilePath="\\\\10.0.15.74\\D$\\Suman\\host.txt";
File f=new File("E:/Suman.txt");
if(f.exists())
{
f.delete();
}
f.createNewFile();
FileObject destn=VFS.getManager().resolveFile(f.getAbsolutePath());
UserAuthenticator auth=new StaticUserAuthenticator(domain, userName, password);
FileSystemOptions opts=new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileObject fo=VFS.getManager().resolveFile(remoteFilePath,opts);
System.out.println(fo.exists());
destn.copyFrom(fo,Selectors.SELECT_SELF);
destn.close();
}
}
This is a program for reading a file from a remote computer and saving it on our local machine as a file E:/Suman.txt.
:, $, :
D:\Suman\Boorla\kpl.txt ,
D$\\Suman\\Boorla\\kpl.txt .
, , .
jar int .
commons-vfs.jar
commons-logging.jar