1
我試圖訪問遠程計算機的目錄遠程目錄(寫服務器和客戶端的部分),並把在JTree的,所以我應該使用System.getProperty(「user.dir來」)
File root=new File(System.getProperty("file.separator"));
FileTreeModel model = new FileTreeModel(root);
jTree1.setModel(model);
後,我設置jTree1,我通過套接字連接發送它,但我不能接受遠程目錄,它打印出它自己的文件目錄。我試圖通過使用遞歸來創建樹模型的所有文件路徑,無論它是否是文件。然而它大約需要3分鐘。我怎麼解決這個問題?訪問通過socket編程
接收我的代碼部分是:
TreeServer = new ServerSocket(805);
TreeSocket = TreeServer.accept();
in = TreeSocket.getInputStream();
TreeObjectInput = new ObjectInputStream(in);
fileTree = (JTree) TreeObjectInput.readObject();
TreeObjectInput.close();
in.close();
TreeServer.close();
送我的代碼
Socket ConnectionSocket = new Socket(remoteIP,805);
File root=new File(System.getProperty("file.separator"));
model = new FileTreeModel(root);
JTree2.setModel(root);
OutputStream os = ConnectionSocket.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(JTree2);
oos.close();
os.close();
添加發送/接收數據的代碼 – Multithreader