Reading and writing windows shared folders in Java programs

Use java to read and write shared folders through jcifs framework, use SMB protocol, and support domain authentication.

Projects often need to access shared folders, such as reading videos, photos, ppts and other files stored in shared folders. So how to use java to read and write windows shared folders?

Using java to access shared folders with all read and write permissions is relatively simple, which is no different from ordinary directories. However, accessing a shared folder on a Windows server that requires user name and password authentication from a Linux server requires a little skill. Here is an open source library jcifs, which can easily meet this requirement.

Jcifs is an open source framework developed in Java language. Accessing remote shared folders through SMB protocol is as simple as accessing local folders. She supports both windows and Linux shared folders. However, the Linux shared folder requires Samba service software (official website: http://www.samba.org/ )。

In addition, it can also be realized by attaching the shared folder to the Linux server. At this time, there is no need to use the SMB protocol. This is not introduced here. Interested children's shoes can ask Du Niang.

To get back to business, Maven relies on the following:

SMB (server message block) communication protocol is a protocol formulated by Microsoft and Intel in 1987. It is mainly used as the communication protocol of Microsoft network. SMB is a protocol in the session layer, presentation layer and a small part of the application layer. By setting "NetBIOS over TCP / IP", samba can share resources not only with local area network hosts, but also with computers all over the world.

Code example:

The ntlmpasswordauthentication class is used for domain authentication and requires three parameters. The first is the domain name. If not, it will be assigned null, the second is the user name and the third is the password. Two application scenarios of SMB protocol are listed below. The smbfile class is very similar to the java file class. Its object can be used to handle the reading and writing of remote shared files.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>