1

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.

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

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:

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); 
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Android
  • 3,828
  • 9
  • 46
  • 79
  • Please refine this question. Mention about your development environment and some more info on what you need. – Kris Nov 03 '11 at 07:17
  • As @Krishnanunni has stated, we would need to know what services the remote server can offer before answering. Can it do SMBFS? SFTP? FTP? NFS? – trojanfoe Nov 03 '11 at 08:04
  • sounds like a job for rentacoder – Will Nov 03 '11 at 09:14

1 Answers1

3

No problem. The UNC convention is without drive letters (C:, D:) in the format

\ \ COMPUTER \ DIR \ DIR \ FILE.

In Java suffices File file = new File("//COMPUTER/DIR/DIR/FILE") or "\ \ \ \ COMPUTER \ \ DIR \ \ DIR \ \ FILE". (I added extraneous spaces around the backslashes.)

file.getPath() will always yield backslashes (Windows).

For the computer name you can use getHostName(), see: http://www.rgagnon.com/javadetails/java-0390.html

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138