• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a text file from different Server

 
Anamika Gubba
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to read a text file from different server. If the text file is in the same server I know how to do this. But how can I connect to the different Server and read the text file. Please let me know. This is how I did if the text file is in the same server. Please someone help me of how to read a text file from different server.

public ArrayList getTxtFile(){

ArrayList ClientHolidaysList = new ArrayList();
try{

BufferedReader in = new BufferedReader(new FileReader("C:/EPMBusiness.txt"));
while(true){

String line = in.readLine();
if(line == null){
break;
}
//Add each line to the List
ClientHolidaysList.add(line);

}
in.close();

}catch(Exception e){

logger.error("Exception in Reading the Epm Business Calendar file :" + e);
}
return ClientHolidaysList;
}

Thanks in advance,
Anamika
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of access do you have to read the file in the other server? HTTP, FTP, SSH, SMB, or any other kind network access?

There are plenty of options to access a file in a remote machine.

If it is a HTTP or FTP server, for instance, you can assemble a URL to file and then call the openConnection() method on that URL. That will automatically create an URLConnection and from it you can get an InputStream or an OutputStream.

With those you can do the rest.

See online documentation about URL.openConnection() and URLConnection.getInputStream().

For other protocols you may need to use third-party libraries. For instance I use special library name JCIFS to work whith the SMB protocol.
[ June 15, 2006: Message edited by: Edwin Dalorzo ]
 
Anamika Gubba
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I will go through the documentation.

-Anamika
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!