Re: How to find the startup directory of my program?



If you;re talking about windows, here is what I use:

.....= (new LocalDir()).getLocalDirRef();

//Ike

/*
* localDir
*
* Utility class to get String and File reference to the local directory
* that the class is executing in.
*/



import java.io.File;
/**
*
* @author Mark Kozel
* @version 1.4.1
* @since Created on December 16, 2002
*/
public class LocalDir
{

public LocalDir()
{
}

/**
* Returns the disk file name of the class that is executing.
*
* @param none
* @return Name of class that is currently executing
*/
public String getClassName()
{
String thisClassName;

//Build a string with executing class's name
thisClassName = this.getClass().getName();
thisClassName = thisClassName.substring(thisClassName.lastIndexOf(".")
+ 1,thisClassName.length());
thisClassName += ".class"; //this is the name of the bytecode file
that is executing

return thisClassName;
}

/**
* Returns the name of the local directory based on the results of a call
to getClassName()
*
* @param none
* @return Name of directory that contains the executing class
*/
public String getLocalDirName()
{
String localDirName;

//Use that name to get a URL to the directory we are executing in
java.net.URL myURL = this.getClass().getResource(getClassName());
//Open a URL to the our .class file

//Clean up the URL and make a String with absolute path name
localDirName = myURL.getPath(); //Strip path to URL object out
localDirName = myURL.getPath().replaceAll("%20", " "); //change %20
chars to spaces

//Get the current execution directory
localDirName =
localDirName.substring(0,localDirName.lastIndexOf("/")); //clean off the
file name

return localDirName;
}

/**
* Returns a File reference to the local directory based on the results
of a call to getClassName()
*
* @param none
* @return File object that points to the local directory
*/
public java.io.File getLocalDirRef()
{
File myFileObj;
//Make the file object and return it
myFileObj = new File(getLocalDirName());
return myFileObj;
}

}


.



Relevant Pages

  • Re: Making a group of objects up and down
    ... This will be evaluate, before animate executing. ... there are definitely disadvantages to passing a string literal here. ... Why 'animate' isn't parse when i call setTimeout? ... A Function object is also _not_ evaluated when a reference to it is passed ...
    (comp.lang.javascript)
  • RE: How to save html tags at SQL Server?
    ... If you are executing a string, ... It would be safer for you to use the SqlCommand object and define a parameter ... with a specified type such as SqlDbType.Text or SqlDbType.VarChar (depending ... the data that would normally be invalid when executing a string. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Help DLL calling in Excel 2007 crashes
    ... functions calls a function in a DLL and when that DLL function returns, ... VBA continues executing by starting the same VBA function over. ... ByRef szCompany As String, ByRef szCode As String) As Long ...
    (microsoft.public.excel.programming)
  • Re: Insert Data
    ... This is my function for executing UPDATE, ... You just supply the SQL statement and the connection ... Public Function ExecDB(ByVal ExecuteQuery As String, ...
    (microsoft.public.dotnet.languages.vb)