<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
java nfs是什麼,讓我們一起了解一下?
NFS是基於UDP/IP協議的應用,其實現主要是採用遠程過程調用RPC機制,RPC提供了一組與機器、操作系統以及低層傳送協議無關的存取遠程檔案的操作。RPC採用了XDR的支援。XDR是一種與機器無關的數據描述編碼的協議,他以獨立與任意機器體系結構的格式對網上傳送的數據進行編碼和解碼,支援在異構系統之間數據的傳送。
NFS的特點是什麼?
1、提供透明檔案訪問以及檔案傳輸。
2、容易擴充新的資源或軟件,不需要改變現有的工作環境。
3、 高性能,可靈活配置。
NFS的工作原理是什麼?
1、透過使用NFS,用戶和程序可以像訪問本地檔案一樣訪問遠端系統上的檔案,使得每個計算機的節點能夠像使用本地資源一樣方便地使用網上資源。換言之,NFS可用於不同類型計算機、操作系統、網絡架構和傳輸協議執行環境中的網絡檔案遠程訪問和共享。
2、使用客戶端/服務器架構,由一個客戶端程序和服務器程序組成。服務器程序向其他計算機提供對檔案系統的訪問,其過程稱爲輸出。NFS客戶端程序對共享檔案系統進行訪問時,把它們從NFS服務器中“輸送”出來。檔案通常以塊爲單位進行傳輸。
如何編寫java代碼讀出遠程客戶端的檔案內容?
使用的包有 jftp.jar
import java.io.File;import java.io.FileFilter;import java.io.IOException; import com.sun.nfs.XFileExtensionAccessor;import com.sun.xfile.*;import net.sf.jftp.system.logging.Log; import java.io.*;import java.util.ArrayList;import java.util.List; /** * Created by fd on 2017/8/14. */public class NFS { String url; XFile xfile; public void NFSconnection(String ip,String dir) { url = "nfs://" + ip + "/" + dir;//創建連接 xfile = new XFile(url); //調用exists()判斷是否連接成功 if (xfile.exists()) { System.out.println("URL is OK!"); } else { System.out.println("URL is Bad!"); return; } } public void coming(String pathname) throws IOException { String path[] = pathname.split("/");//切割,如果服務器是unix系統,更改爲"" String[] fileList = new String[1024];//設定接收目錄掃描的長度,暫時設定爲1024 fileList = xfile.list();//缺少這一句的話,會出現找不到檔案的錯誤 XFile temp; XFileInputStream in = null; for(String splittext:path){ url = url+"/"+splittext; temp = new XFile(url); in = new XFileInputStream(temp); fileList = temp.list(); } BufferedReader reader = new BufferedReader(new InputStreamReader(in,"GBK")); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } public static void main(String[] args) throws IOException { String ip ="172.19.152.32"; String dir = "nfs"; NFS nfs = new NFS(); nfs.NFSconnection(ip,dir); nfs.coming("com/gdin/edu/test1.txt"); }}