title: Java: reading file from remote path
body: <p>In Java, I would to read file from remote path into string. Local point and remote point are on the same network. Local point is Windows, remote point is Linux.
  To read file from local path I use:</p>
  
  <pre><code>filecontent = new Scanner(new File(...local path...)).useDelimiter("\\Z").next();
  </code></pre>
  
  <p>Instead, for remote path I found more solutions that doesn't work, for example:</p>
  
  <ol>
  <li>File(..remote path..) as <strong>"\\remote host\remote dir\..\test.txt"</strong></li>
  <li><strong>File(new URI("file:///..remote path.."));</strong></li>
  <li>Mounting path in drive Z: and read as <strong>new File("z:\test.txt");</strong></li>
  </ol>
  
  <p>I found one other solution like <strong>JCIFS Samba library</strong> that I'll use if there isn't other ways. First, I would ask you if there's another way that use only <strong>new File(..)</strong>.</p>
  
  <p>Thank you for your attention.</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>I get remote path from my Oracle db. Now in my table there's "z:\test.xml".
  Using <strong>new File("z:\test.xml");</strong> the stacktrace is:</p>
  
  <pre><code>Java.io.FileNotFoundException: z:\test.xml (Impossibile trovare il percorso specificato)
      at java.io.FileInputStream.open0(Native Method)
      at java.io.FileInputStream.open(Unknown Source)
      at java.io.FileInputStream.&lt;init&gt;(Unknown Source)
      at java.util.Scanner.&lt;init&gt;(Unknown Source)
      at it.latraccia.aruba.client.ClientFatturaElettronicaAruba.runClientFatturaElettronicaAruba(ClientFatturaElettronicaAruba.java:106)
      at it.traccia.tracciaHub.TracciaHub.doGet(TracciaHub.java:82)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>line 106 of ClientFatturaElettronicaAruba.runClientFatturaElettronicaAruba(ClientFatturaElettronicaAruba.java:106:</p>
  
  <pre><code>filebase64 = new Scanner(new File(responsegetparaminviafattura.getFilePath())).useDelimiter("\\Z").next();
  </code></pre>
  
  <p><strong>UPDATE 2</strong>: <em>Minimal, Complete, and Verifiable example</em></p>
  
  <p>My web application run under Tomcat 8.0 with Java 1.8</p>
  
  <p><strong><em>(see method "doGet")</em></strong></p>
  
  <pre><code>public class Test extends HttpServlet {
  
  private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public Test() {
      super();
      // TODO Auto-generated constructor stub
  }   
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  
      try {       
          File f = new File("z:\\test.xml");
  
          if(f.exists()) {
              request.setAttribute("ret",f.toString());
          }
          else {
              request.setAttribute("ret","file not exist");
          }
  
          visualizzaJsp(request,response,"/index.jsp");
      } catch (IOException e) {
          request.setAttribute("ret","IOException");
          e.printStackTrace();            
      } catch (ServletException e) {
          request.setAttribute("ret","ServletException");
          e.printStackTrace();            
      }       
  
  }   
  
  public void visualizzaJsp (HttpServletRequest request, HttpServletResponse response,String pathDispatcher)throws IOException, ServletException{
  
      RequestDispatcher dispatcher =this.getServletContext().getRequestDispatcher(pathDispatcher);
      dispatcher.forward(request, response);
  
  }   
  </code></pre>
  
  <p>}</p>
  
  <p>The output in my index.jsp is "<strong>file not exist</strong>".</p>