Install Yum install Samba in centos
Um install samba-client samba-SWAT dependent packages samba-common, samba-winbind-clients, and libsmbclient will be automatically installed.
The configuration is as follows: http: // Www.cnblogs.com/whiteyun/archive/2011/05/27/2059670.html Do not place the shared folder in the root directory and put it in the Home Directory (I am wasting my time here)
Reference URL:
Http://blog.csdn.net/jastar/article/details/5639152
Http://www.cnblogs.com/whiteyun/archive/2011/05/27/2059670.html
Http://blog.csdn.net/zdwzzu2006/article/details/4209877
Http://www.samba.org/
Http://jingyan.baidu.com/article/8cdccae9be9367315413cde9.htmlCodeAs follows:
Import java. Io. bytearrayoutputstream;
Import java. Io. ioexception;
Import java.net. malformedurlexception;
Import java.net. unknownhostexception;
Import jcifs. SMB. smbexception;
Import jcifs. SMB. smbfile;
Import jcifs. SMB. smbfileinputstream;
Public class testsamba {
Public static string readfromfile (smbfile filename, string encoding) throws ioexception {
Bytearrayoutputstream baos = new bytearrayoutputstream ();
Smbfileinputstream FCM = new smbfileinputstream (filename );
Byte [] cbuf = new byte [1, 1024];
Int Len = 0;
While (LEN = FS. Read (cbuf ))! =-1 ){
Baos. Write (cbuf, 0, Len );
}
FCM. Close ();
Baos. Close ();
String TXT = baos. tostring (encoding );
Return txt;
}
Public static void main (string [] ARGs ){
Try {
// Smbfile file = new smbfile ("SMB: // root: 123456@192.9.117.111/guoing /");
//
// If (file. exists ()){
// Smbfile [] files = file. listfiles ();
// For (INT I = 0; I <files. length; I ++ ){
// System. Out. println (files [I]. tostring ());
//}
//}
//
// String res = sambautil. readfile ("192.9.117.111/guoing/a.txt", "root", "123456 ");
String Path = "SMB: // 192.9.117.81/**/a.txt ";
// Path = "SMB: // root: 123456@192.9.117.111/guoing/dump ";
Smbfile file = new smbfile (PATH );
String res = readfromfile (file, "GBK ");
System. Out. println (RES );
} Catch (exception e ){
E. printstacktrace ();
}
}
}
Test successful ~