2009年5月4日 星期一

使用JCIFS存取samba folder

JCIFS web site: http://jcifs.samba.org/

Sample code:

jcifs.Config.setProperty("jcifs.smb.client.domain", "APNET");
jcifs.Config.setProperty("jcifs.smb.client.username", "apuser");
jcifs.Config.setProperty("jcifs.smb.client.password", "appassword");
java.io.FileInputStream input = new java.io.FileInputStream("d:/temp/test.txt");
jcifs.smb.SmbFileOutputStream output = new jcifs.smb.SmbFileOutputStream(
        "smb://hostname/upload$/test.txt");
byte[] b = new byte[8192];
int n;
while ((n = input.read(b)) > 0) {
    System.out.write(b, 0, n);
    output.write(b, 0, n);
}
input.close();
output.close();