Этот пример разделяет конкретный код Java с использованием SMB для чтения удаленных файлов для вашей ссылки. Конкретный контент заключается в следующем
пакет com.yss.test.filereadwriter; Импорт java.io.bufferedinputstream; Импорт java.io.bufferedOutputStream; Импорт java.io.file; импортировать java.io.fileinputstream; Импорт java.io.fileOutputStream; импортировать java.io.ioexception; импортировать java.io.inputstream; импортировать java.io.outputstream; Импорт java.net.malformedurlexception; Импорт jcifs.smb.smbfile; Импорт jcifs.smb.smbfileinputstream; Импорт jcifs.smb.smbfileoutputstream; открытый класс remoteAccessData {/** * @param args * @throws ioexception */public static void main (string [] args) throws 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 * remote path Smb: //192.168.75.204/test/new Text Document.txt * @throws ioexception */public void smbget1 (string remoteurl) throws ioexception {smbfile smbfile = new smbfile (remoteurl); int length = smbfile.getContentLength (); // Получить байтовый буфер размера файла [] = новый байт [длина]; Smbfileinputstream in = new smbfileinputstream (smbfile); // Создать поток ввода файла SMB while ((in.read (buffer))! = -1) {System.out.write (buffer); System.out.println (buffer.length); } in.close (); } // Скачать файл из общего каталога/** * Метод 2: * Формат пути: SMB: //192.168.75.204/test/ Создать новый текстовый документ.txt * smb: // username: [email protected]/test * @param remoteurl * remote path * @param loc remoteurl, String localdir) {inputstream in = null; OutputStream Out = null; try {smbfile remotefile = new smbfile (remoteurl); if (remotefile == null) {System.out.println («Общий файл не существует»); возвращаться; } String filename = remotefile.getName (); File localfile = new File (localdir + file.separator + filename); in = new BufferedInputStream (новый SMBFileInputStream (RemoteFile)); out = new BufferedOutputStream (New FileOutputStream (LocalFile)); Byte [] buffer = новый байт [1024]; while (in.read (buffer)! = -1) {out.write (buffer); Buffer = новый байт [1024]; }} catch (Exception e) {e.printstackTrace (); } наконец {try {out.close (); in.close (); } catch (ioException e) {e.printstackTrace (); }}} // upload file public static void smbput (string remoteurl, string localfilepath) {inputstream in = null; OutputStream Out = null; try {file localfile = new File (localfilePath); String fileName = localfile.getName (); Smbfile remotefile = new smbfile (remoteurl + "/" + filename); in = new BufferedInputStream (New FileInputStream (LocalFile)); out = new BufferedOutputStream (новый SMBFileOutputStream (RemoteFile)); Byte [] buffer = новый байт [1024]; while (in.read (buffer)! = -1) {out.write (buffer); Buffer = новый байт [1024]; }} catch (Exception e) {e.printstackTrace (); } наконец {try {out.close (); in.close (); } catch (ioException e) {e.printstackTrace (); }}} // Удаленный URL SMB: //192.168.0.77/test // Если вам нужны имя пользователя и пароль, точно так же: // smb: // username: [email protected]/test}Выше всего содержание этой статьи. Я надеюсь, что это будет полезно для каждого обучения, и я надеюсь, что все будут поддерживать Wulin.com больше.