Simple Java Access Shared File

xiaoxiao2021-03-06  18

1. Developing tools used: (1), Eclipse: http://www.eclipse.org (2), JCIFS: http: //jcifs.samba.org/

Second, preface:

In the Microsoft Network System, the SMB (Server Message Block, Service Message Block) protocol is Windows for Workgroup (WFWG), Windows 95, Windows NT, and LanManager for implementing a shared local domain file and printer. For a local domain network constructed by Linux and Windows NT, Samba is a software package for the SMB household sequence / server program provided for Linux, which is a magnetic disk space and printer that realizes Windows and Linux. General Network File System is referred to as CIFS, which is actually a standard protocol shared by Windows platform files, which is the bottom level implementation protocol for Windows Explorer, network neighbor, and mapping network drives. Java has natural platform innocence, using Java access to any type of server or shared file system on the client, and the written software products can run in any platform, so the Java access shared file system has a unique advantage in enterprise applications. .

CIFS implementation in Java

JCIFS is an implementation of CIFS in Java. It is a Samba organization in the spirit of Linux and is responsible for maintenance of development. This project focuses on the design and implementation of the CIFS protocol using the Java language. They designed JCIFS into a complete, rich, scalable and thread-safe client library. This library can be applied to a variety of Java virtual machine access to comply with the network resources of the CIFS / SMB network transfer protocol. Similar to the interface of java.io.file, it is proven to be effective and easy to use in multi-threaded mode of operation. The latest version of JCIFS is JCIFS-1.1.9

Three: Configuration: (1), set the running environment, add JCIFS-1.1.9.jar to the project -----> Properties -------> Java Builder PATH ------> Library ---------> Add external JAR OK! (2), establish a shared folder and shared file on another computer, this example is: Test, Response.txt (3), compile the following programs

Fourth, the code: import jcifs.smb.smbfileinputstream; public class readsharefile {

public static void main (String [] args) {byte buffer [] = new byte [1024]; int readed = 0; try {SmbFileInputStream in = new SmbFileInputStream ( "smb: // administrator: 122122@192.168.0.22/test/ Response.txt "); // Establish a SMB file input stream while ((Readed = in.read (buffer))! = -1) {system.write (buffer);}} catch (exception e) {e. PRINTSTACKTRACE ();}}}

Five: Code Description: SMB: // Administrator: 122122@192.168.0.22/test/response.txtsmb: protocol named SMBADMINISTRATOR: Login User Note: Login for shared file machine 122122: Login password Note: Password and login user The name is ":" 192.168.0.22: shared file machine iptest: shared folder response.txt: shared file Special explanation: Foreword is reproduced in: Xue Guyu

转载请注明原文地址:https://www.9cbs.com/read-40330.html

New Post(0)