title: File Transfer RMI
body: <p>I am just following a tutorial on how to send files using RMI.</p>
  
  <p>Tutorial: <a href="http://www.oracle.com/technetwork/articles/javase/rmi-corba-136641.html" rel="nofollow">Link</a></p>
  
  <p>I encounter an error when i try to run my server. The only change i have made different from the tutorial is i have changed my port to 1097 instead of the default 1099.</p>
  
  <p>How can i resolve this error?</p>
  
  <p>This is the error i receive:</p>
  
  <pre><code>C:\Program Files\Java\jdk1.7.0_09\bin\FT_RMI&gt;java -Djava.security.policy=policy.
  txt FileServer
  FileServer: access denied ("java.net.SocketPermission" "127.0.0.1:1097" "connect
  ,resolve")
  java.security.AccessControlException: access denied ("java.net.SocketPermission"
   "127.0.0.1:1097" "connect,resolve")
          at java.security.AccessControlContext.checkPermission(Unknown Source)
          at java.security.AccessController.checkPermission(Unknown Source)
          at java.lang.SecurityManager.checkPermission(Unknown Source)
          at java.lang.SecurityManager.checkConnect(Unknown Source)
          at java.net.Socket.connect(Unknown Source)
          at java.net.Socket.connect(Unknown Source)
          at java.net.Socket.&lt;init&gt;(Unknown Source)
          at java.net.Socket.&lt;init&gt;(Unknown Source)
          at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
  ource)
          at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
  ource)
          at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
          at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
          at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
          at sun.rmi.server.UnicastRef.newCall(Unknown Source)
          at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
          at java.rmi.Naming.rebind(Unknown Source)
          at FileServer.main(FileServer.java:11)
  </code></pre>
  
  <p>Line 11 is Naming.rebind().</p>
  
  <p>Here:</p>
  
  <pre><code>FileInterface fi = new FileImpl("FileServer");
       Naming.rebind("//127.0.0.1:1097/FileServer", fi);
  </code></pre>
  
  <p>I have tried changing the address to localhost, but the same error occurs.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Point to the specific java policy file, either in JRE folder or a specific policy file.</p>
  
  <pre><code>java -Djava.security.policy="C:\\FT_RMI\\java.policy" FileServer
  </code></pre>