Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to browse RMI server disk file system with java.io.File?
    primarykey
    data
    text
    <p>I want a RMI server / client system where you can browse the files on the server with a client. In this case the server is a Debian and the client runs on Windows.</p> <p>I tried to have the server hold a <code>File</code> object pointing to the currently seen directory and show all files in that directory in a <code>List</code> on the client.</p> <p>The problem is, when I call a method returning me <code>file.listFiles()</code>, I don't get the files on the server but on the client or <code>FileNotFoundException</code> as if the server would run on the client. The Java <code>File</code> API seems to use the root directories on the computer where the client runs on and not the server.</p> <p>Simpler said: I want a file explorer on the client showing me the server file system.</p> <p>Edit:</p> <pre><code>public class ClientMain { /** * @param args */ public static void main(String[] args) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } View view = new View(); view.setVisible(true); try { String name = "Remote"; Registry registry = LocateRegistry.getRegistry("127.0.0.1"); IRemote model = (IRemote) registry.lookup(name); view.setModel(model); view.update(); } catch (Exception e) { System.err.println("Remote Exception"); e.printStackTrace(); } } } public class View extends JFrame implements IView{ JList list; IRemote model; public View() { super(); this.setVisible(true); this.setDefaultCloseOperation(EXIT_ON_CLOSE); list = new JList(); this.add(list); } public IRemote getModel() { return model; } public void setModel(IRemote model) { this.model = model; } public void update(){ try { this.list.setListData(model.getFileList()); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public interface IRemote extends Remote { public String[] getFileList() throws RemoteException; } public class Model implements IRemote{ File current; public Model() { super(); current = new File("."); } public String[] getFileList() { return current.list(); } public void setCurrentDirectory(String current) { this.current = new File(current); } } public class ServerMain { public static void main(String[] args) { new ServerMain(); } public ServerMain() { super(); Model model = new Model(); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { String name = "Remote"; IRemote stub = (IRemote) UnicastRemoteObject.exportObject(model, 0); Registry registry = LocateRegistry.getRegistry(); registry.rebind(name, stub); } catch (Exception e) { System.err.println("Controller exception:"); e.printStackTrace(); } } } </code></pre> <p>This is what i am trying to do. Here the Server binds a Model to the Registry. The Client looks up the Model give the Model to the View and the view calls getFileList() from the Model. With the "." File I get the Directory where the Programm is located. Since it's relative I get all the File on the Client where the Client Programm is running. If I use a non-relative Directory I get the FileNotFoundException because the Client does not have this path. Hope that makes it even clearer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload