• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to read config file from other mahine using java

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jim,
I think ya that can be possible, thanks for the reply.
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic