• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to read config file from other mahine using java

 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I am reading config file form my harddisk and follwing is the code.
Code starts from here :-
import java.io.*;
import java.util.*;
public class ReadProperties
{
public Properties getProperties()
{
String FileName = "TestProperty.properties";
System.out.println("File name "+FileName);
InputStream is = getClass().getResourceAsStream(FileName);
Properties dbProps = new Properties();
try
{
dbProps.load(is);
}
catch (Exception e)
{
System.out.println("Can't read the properties file. " +e.getMessage());
dbProps =null;
}
return dbProps;
}
public static void main(String[] args)
{
ReadProperties readProperties = new ReadProperties();
Properties dbProp = readProperties.getProperties();
String userName = dbProp.getProperty("userName");
System.out.println("User name "+userName);
}
}
Code ends here .
Above code works fine.
Now the problem is this config file is lying on the other server.What should i do..??
Can anyone throw some light ...on this
(pls i don't want to use RMI or JNDI in this)
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest method is probably to create a URL object with the URL of the remote file. Then use openConnection() to get an InputStream, and process it just as you did before. Otherwise you'll need to create a Socket, I imagine - but the URL is probably simpler. I suggest posting to Sockets and Internet Protocols if you have troubles.
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jim,
I think ya that can be possible, thanks for the reply.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic