load one propertiens file into one class

X

_XaToA_

hello
i am trying for programing one java class and into one directory, one level
up directory, i have one properties file miprop.properties called.
i am trying to load this file but always my compiler says me
FileNotFoundError
i am trying with this:
try{
propFile = new FileInputStream("miprop.properties");
Properties p = new Properties(System.getProperties());
p.load(propFile);
System.setProperties(p);
System.getProperties().list(System.out);
}catch(Exception e){
e.printStackTrace();
}


can you helpo me?
thanks
 
A

Anthony Borla

_XaToA_ said:
hello
i am trying for programing one java class and into one
directory, one level up directory, i have one properties
file miprop.properties called. i am trying to load this
file but always my compiler says me FileNotFoundError
i am trying with this:
try{
propFile = new FileInputStream("miprop.properties");
Properties p = new Properties(System.getProperties());
p.load(propFile);
System.setProperties(p);
System.getProperties().list(System.out);
}catch(Exception e){
e.printStackTrace();
}

Where is the file located ? As it stands, the file is expected to be in the
current directory, the one from which the application is launched [i.e. the
location in 'user.dir']; if stored elsewhere, you need to provide the full
path.

An example of how you might furnish such location information:

Properties properties = System.getProperties();

String homeDir = properties.getProperty("user.home"),
currDir = properties.getProperty("user.dir");

// or: "/work/data" on *NIX systems
String dataDir = "c:\\work\\data";

String fileSeparator = properties.getProperty("file.separator");

then doing something like:

String fname = "miprop.properties";

StringBuffer propPath =
new StringBuffer(homeDir).append(fileSeparator).append(fname);

// or
StringBuffer propPath =
new StringBuffer(currDir).append(fileSeparator).append(fname);

// or
StringBuffer propPath =
new StringBuffer(dataDir).append(fileSeparator).append(fname);

propFile = new FileInputStream(propPath);

I hope this helps.

Anthony Borla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top