Obtaining directory from with the source file

M

mshetty

Hi,

We are new Java. We have a hierachy <Inst Dir>/CNV/src/com/xyz/abc for
the source code and <Inst Dir>/CNV/lib/com/xyz/abc for the class files.
The jars are created in CNV. There are some shell scripts in CNV to
execute the class files.
We want to do the following:
1. Create logs in CNV.

The <Inst Dir> could vary from one installation to another. Is there a
way of finding out this path from the java file in <Inst
Dir>/CNV/src/com/xyz/abc

Thanks and Regards,
M Shetty
 
A

Andrew Thompson

..We have a hierachy .. <Inst Dir>/CNV/lib/com/xyz/abc for the class files. ....
We want to do the following:
1. Create logs in CNV.

That is not a good place to put the logs.

A better place might be something like..
{$user.home}/com/xys/abc/ourapplication.log

Or, better yet, let the user choose the location for
themselves, and simply store a string naming the
path to it, in..
{$user.home}/com/xys/abc/logpath.txt

Andrew T.
 
M

Manish Pandit

Andrew said:
That is not a good place to put the logs.

A better place might be something like..
{$user.home}/com/xys/abc/ourapplication.log

Or, better yet, let the user choose the location for
themselves, and simply store a string naming the
path to it, in..
{$user.home}/com/xys/abc/logpath.txt

Andrew T.

I completely agree with Andrew.

Log files do not belong in the application directory - almost always
there is a separate path (often separate drive which gets backed up,
etc.) for logs. Anyway, if you still insist on putting the logs in
installation folder, try this :
new File(".").getAbsolutePath( );
to get the "current" location as seen by the class calling this API.
Take a look at java.io.File API, there are methods to get parent
folder, etc. in there.

-cheers,
Manish
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top