title: Fetching file and path from network using java
body: <p>I need to fetch a file from network, and save the associated file path using UNC convention. And I need to import data from that file (say Excel sheet) later at particular time. Can any one suggest me one sample program so that I can at least fetch the file from network and store the file path.</p>
  
  <p>I am using a swing application and in that I need the excel sheet to get imported using a scheduler which triggers at some particular time. Earlier I was using local host Jboss, but now I need that if any one sets a path according to its own computer, path should be stored in UNC format so that file get imported automatically at the predefined time to the database which is on any other machine. So basically I need to store the path according to UNC format. I am using Swing and spring in my application</p>
  
  <p>There are a few more issues regarding that like if the folder is not sharable how would it will import at particular time. Apart from that if even shared it would store whole of the path, but I want only that portion of url from which it is shared. This is what I use in my code:</p>
  
  <pre><code>java.net.InetAddress i = java.net.InetAddress.getLocalHost();
  System.out.println(i);                  // name and IP address
  System.out.println(i.getHostName());    // name
  System.out.println(i.getHostAddress()); // IP address only
  
  StringBuffer s = new StringBuffer(filePath);
  StringBuffer AfterRemoval=s.delete(0,1);
  
  String finalFilePath;
  StringBuffer sb = new StringBuffer(40);
  finalFilePath = sb.append(i.getHostName()).append(AfterRemoval).toString();
  System.out.println(finalFilePath); 
  </code></pre>