이 예제는 SMB를 사용하여 특정 Java의 특정 코드를 공유하여 참조 용 원격 파일을 읽습니다. 특정 내용은 다음과 같습니다
패키지 com.yss.test.filereadwriter; import java.io.bufferedInputStream; import java.io.bufferedOutputStream; import java.io.file; import java.io.fileInputStream; import java.io.fileoutputStream; import java.io.ioexception; import java.io.inputstream; import java.io.outputStream; java.net.malformedurlexception import; JCIFS.SMB.SMBFILE 가져 오기; jcifs.smb.smbfileinputstream 가져 오기; JCIFS.SMB.SMBFILEOUTPUTSTREAM 가져 오기; 공개 클래스 remoteaccessdata {/** * @param args * @throws ioexception */public static void main (string [] args)은 ioexception {smbget1 ( "smb : //192.168.75.204/test/new text.txt"); smbget ( "smb : //192.168.75.204/test/new text document.txt", "e :/"); }/** * 메소드 1 : * * @Param RemoteUrl * 원격 경로 smb : //192.168.75.204/test/new text document.txt * @throws ioexception */public static void smbget1 (String RemoteUrl)은 ioexception {smbfile smbfile = 새로운 smbfile (remoturl); int length = smbfile.getContentLength (); // 파일 크기 바이트 버퍼를 가져옵니다 [] = 새 바이트 [길이]; smbfileInputStream in = 새로운 smbfileInputStream (smbfile); // smb 파일 입력 스트림을 만듭니다. System.out.println (buffer.length); } in.close (); } // 공유 디렉토리에서 파일 다운로드/** * 메소드 2 : * 경로 형식 : smb : //192.168.75.204/test/ 새 텍스트 문서 만들기 .txt * smb : // username : [email protected]/test * @param remoteurl * @param localdir * public void void void void void void void void void void void void void void void void void void void void void void void void void smbet. localDir) {inputStream in = null; outputStream out = null; try {smbfile implicfile = new smbfile (remoteurl); if (remoteFile == null) {system.out.println ( "공유 파일이 존재하지 않음"); 반품; } string filename = remoteFile.getName (); localfile = 새 파일 (localDir + file.separator + filename); in = new bufferedInputStream (new smbfileInputStream (remoteFile)); out = new bufferedOutputStream (새 파일 아웃 putStream (localFile)); 바이트 [] 버퍼 = 새로운 바이트 [1024]; while (in.read (buffer)! = -1) {out.write (buffer); 버퍼 = 새로운 바이트 [1024]; }} catch (예외 e) {e.printstacktrace (); } 마침내 {try {out.close (); 넣다(); } catch (ioexception e) {e.printstacktrace (); }}} // 파일 업로드 공개 정적 무효 outputStream out = null; try {file localfile = 새 파일 (localfilepath); 문자열 filename = localfile.getName (); smbfile implicfile = 새로운 smbfile (remoteurl + "/" + filename); in = new bufferedInputStream (new FileInputStream (localFile)); out = new bufferedOutputStream (new SMBFileOutputStream (remoteFile)); 바이트 [] 버퍼 = 새로운 바이트 [1024]; while (in.read (buffer)! = -1) {out.write (buffer); 버퍼 = 새로운 바이트 [1024]; }} catch (예외 e) {e.printstacktrace (); } 마침내 {try {out.close (); 넣다(); } catch (ioexception e) {e.printstacktrace (); }}} // 원격 URL smb : //192.168.0.77/test // 사용자 이름과 암호가 필요한 경우 : // smb : // username : [email protected]/test}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.