Samba reads Linux shared files

Source: Internet
Author: User
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 ~

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.