Get current directory?

Hello
How do I get the directory a java program is running in?

System.getProperty("user.dir")

Similar Messages

  • Cd_links: could not get current directory

    I am installing Oracle8 in Linux and that's the error that I am
    getting: cd_links: could not get current directory
    Does anyone know where is cd_links?
    null

    Claudia (guest) wrote:
    : I am installing Oracle8 in Linux and that's the error that I am
    : getting: cd_links: could not get current directory
    : Does anyone know where is cd_links?
    Which Oracle version are you installing? It's the Enterprise
    Edition or the Standard Edition, did you download it from the
    web? or you got the cd?
    null

  • Getting current directory from an applet

    Hi. How can I get the current directory of my applet running on web without having to worry about permissin. I used the one below:
    curDir = System.getProperty("user.dir");
    but I get this error:
    ava.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
    any substiture for this? Thanks.

    You should be using URLs or similar approaches, and avoiding File, which will
    never work with an ordinary applet.
    InputStream in = this.getClass().getResourceAsStream("file.txt");That assumes the txt file is in the same place as the current classes .class file.
    For example, the same folder or that they are jarred in the same "folder" in the jar.
    You can also use a URL directly:
    URL url = ...
    InputStream in = url.openStream();and you can construct that URL with the help of Applet methods getDocumentBase or getCodeBase:
    URL url = new URL(this.getDocumentBase(), "file.txt");That assumes the txt file is in the same folder as the html file in which the applet is embedded.

  • Get current directory(without user.dir)!!!!

    Dudes,
    need help badly... i need to get the current directory of the jar file where it gets launched from. Since the launching takes place from an html file, the system property "user.dir" does not get set to the current directory. Both the html as well as the jar file is in the same location.
    so in short, i need to get the current dir without using the user.dir that i can later set it explicitly thru my program(to the current dir)

    "Search the CLASSPATH for the first occurence of your jar file... but FFS only do it once, and save the result"
    Cud ya elaborate that statement.
    Also, the reason i wanna know is this : my jar file references all the images that it uses, thru a relative path(./a/b/c.....). So wen i simply double click the jar file, the relative path("./") gets replaced with the current workin directory(from user.dir) and fetching of images works perfectly. But if it is launched via html, the user.dir does not get set to the current working dirctory and as a result the jar file looks for its images in the default location which is the desktop. so it doesnt work
    Now that the context is clear, is there a way out???? or is there any way in which i can set the user.dir from the html itself(maybe by using javascript or somethin??)

  • Getting current directory for JFileChooser

    I'm trying to construct a JFileChooser that uses the current directory as its view (and not the default Windows "My Documents" directory path). How can I get the current directory path? File definately doesn't have anything, Toolkit neither.

    I had the same exact question a while ago. The solution is quite simple.
    JFileChooser j = new JFileChooser(".");

  • Getting current directory

    Is there some way to get the current directory path in java?
    -Kevin

    Use
    System.getProperty("user.dir")
    you can get the directory in which you start your java application.

  • How to get current directory and enviroment variables

    Hello, 
       1.- Is there a global variable to get the actual (project, where is DSB and DSQ files) directory? 
       2.- Is there a way to get User directory like reading enviroment variables from Operative System? 
    Thanks in advance.
    PD: I'm using Dasylab12
    Solved!
    Go to Solution.

    Yes, use System Strings
    For example, ${DATA_FOLDER}.
    The easiest way to get the list is to right click and select Global Strings. The bottom half of the dialog box lists system strings, including date, time, the name of the worksheet, with or without path, the DEFAULT folders for worksheet, data, other, black box, etc. 
    - cj
    Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab.

  • How to get  current working directory of the ftp server,in java application

    Hi All,
    I?m FTP?ing the file using java.net.url.
    Here is the snippet of the code:
    public void ftpFile()throws ChrsException
    try
    System.out.println("FTPing the file '"+localfile+"'");
    OutputStream os = openUploadStream(targetfile);
    FileInputStream is = new FileInputStream(localfile);
    byte[] buf = new byte[16384];
    int noOfBytesRead;
    while (true)
    //Read the data from the source File into buf
    noOfBytesRead = is.read(buf);
    if (noOfBytesRead <= 0)
    break;
    //Writes the data present in the buf to the target file
    os.write(buf, 0, noOfBytesRead);
    os.close();
    is.close();
    close();
    System.out.println ("The file '"+localfile+"' is Sucessfully FTP'd to '"+targetfile+"'");
    catch (MalformedURLException malExcp)
    System.out.println ("Invalid URL. Error in FTP'ing the file: \""+localfile+"\"");
    catch(IOException ioe)
    System.out.println ("Error in FTP'ing the file: \""+localfile+"\"");
    private OutputStream openUploadStream(String targetfile) throws MalformedURLException, IOException
    URL url = null;
    //Creates a URL object with FTP protocol
    if (user == null)
    url = new URL("ftp://" + host + "/" + targetfile + ";type=i");
    else
    url = new URL("ftp://" + user + ":" + password + "@" + host + "/" + targetfile + ";type=i");
    urlc = url.openConnection();
    //Get the OutputStream that writes to this connection.
    OutputStream os = urlc.getOutputStream();
    return os;
    Now I need to find what the current directory is when the user logs in with username and password on to the FTP server in java.
    Thanks in Advance.

    as soon as user logs in he is taken to the directory
    "ftproot/pub/abc".
    now If I execute pwd command , is hould be able to
    get to know tht user is under "ftproot/pub/abc"Three respected posters, well two plus me ;-), have just told you otherwise. The information about the current directory is (a) secure and (b) useless to the user, as he can't do anything with it. The user doesn't want to know that at all and you shouldn't try to tell him. And in any case FTP doesn't support it, again for security reasons, so you can't do it.
    Just accept it.

  • How to get the path of current directory?

    I have the Java servlet to produce text file, and it produces to C:\hello.txt,
    but I want to output in the current directory as the Java File:
    i.e. C:\jakarta-tomcat-4.1.30\webapps\ExtendedGUI\WEB-INF\classes
    try
         PrintWriter out = new PrintWriter(new FileWriter("hello.txt"));
         out.println("HELLO");
         out.close();
    catch(IOException e)
    any ideas?? Thanks!!

    The current directory is defined as the directory that you started your servlet container from. In your case, it was c:\. If you want it to fall into the same directory as your class files, I would start by finding out what TOMCAT_HOME or whatever container you're using is and adding to the directory until you get to your class directory. Make sense?
    The easiest way is to read the output directory from a properties file as a resource or a hardcoded path.
    HTH

  • How to get absolute path of current directory?

    Hi, everyone!
    I want to get the absolute path of current directory.
    Are there some APIs that I can use?
    Thanks in advance,
    George

    Hi, dheeraj_tak buddie!
    What do you mean in your reply?
    "in File class u have all this methods for getting absolute path "regards,
    George

  • Can't get current working directory

    I can't figure out how to get the current directory my applet is running from. I want to loop through the currentdirectory/folderA. Below is my code:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.lang.*;
    import javax.swing.JApplet;
    import javax.swing.*;
    import java.net.*;
    public class Refresh4 extends JApplet{     
         String curDir = System.getProperty("user.dir");
        String myFile = curDir+"/folderA";//folderA within the directory that the applet is in
        File f = new File(myFile);
        long orig;
        long upd=0;
        long comp=0;
        javax.swing.Timer timer;
        int j = 1;
         public void init(){//initial run class, runs create gui once and sets up timer
            try {
                javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
            } catch (Exception e) { }
            timer = new javax.swing.Timer(2000,taskPerformer);//runs every 2 seconds
              timer.start();//starts timer
      ActionListener taskPerformer = new ActionListener() {//called by timer every 2 seconds, executes FileReader
          public void actionPerformed(ActionEvent evt) {
               j++;
               FileReader(j);
    public void FileReader(int j){//reads all files in directory and checks their modified time/date
         File[] files = f.listFiles();
              for (int i=0;i<files.length;i++){
                   File nFile = files;
                   orig = nFile.lastModified();
                   if (orig>upd){
                        upd = orig;
              if(upd>comp){
                   comp = upd;
                   if(j>2){
                   try {
                        getAppletContext().showDocument
                        (new URL("javascript:doAlert(\""+j+"\")"));
                   catch (MalformedURLException me) { }          

    String curDir = System.getProperty("user.dir");That does get the current directory.
    However, your applet should not "need" to know this, nor rely on it. If you want to open resources (such as graphic images), those resources should be packaged with the applet (like in a jar file on the server), and the applet would get them using codebase- or classpath- based APIs -- not file system-based APIs.

  • Get current executable directory

    let's say the current start.jar file is running in direct //abc/dc/
    how do I get this directory so I save user customizable configuration to it? I need something that can works on multiple operating system, just just limiting toward windows thanks.

    not sure what I did wrong but I could get all 5 items.
    for (String s : p.childrenNames()) {
                     jTextPane1.setText(s + "");
                }this one returns only "jdumper" and nothing else
    for (String s : p.keys()) {
                     jTextPane1.setText(s + "");
                }returns only the last key stored.
    the weird thing is, Sun wouldn't let us specify which node to write to ...but it allows to retrieve from a certain node. Not sure how does that logic works.
    here is how I write:
    Preferences p = Preferences.userRoot();
    p.put("Operators", jTextField1.getText());
    p.put("Make", jTextField2.getText());
    p.put("Model", jTextField3.getText());
    p.put("Version", jTextField4.getText());
    p.flush();and here is how I get
    jTextField1.setText(p.get("Operators", ""));
    jTextField2.setText(p.get("Make", ""));
    jTextField3.setText(p.get("Model", ""));
    jTextField4.setText(p.get("Version", ""));Is there another way to dump everything out into jTextPane? I'm pretty sure all 4 keys got stored because I was able to retrieve them so they're inside somewhere, I just need to dump them all out into one container.

  • How to get the Current Directory

    Hi,
    I need to tell the system to read a file in my current directory. How do I tell the system what the current Directory Path is
    Thankx in advance...

    It depends on the current working directory from which you start your JVM.
    From DOS or UNIX shell this is the directory where you have come by "cd".
    On Windows you can do the same from Explorer or other file managers: the directory where you are when starting JVM.exe.
    If you define shortcuts - e.g. on the desktop -, you specify it there as the "working directory".
    You can retrieve this directory by
    System.getProperty( "user.dir" )
    Now with File classes:
    Each file name without path will be interpreted as being in this directory.
    Absolute paths are clear.
    But you can't mix this:
    If you specify "test/debug.ini" or "test\\debug.ini" from debug directory: false!
    If you specify "../debug.ini" or "..\\debug.ini" from debug/test directory: false!
    Do it this way:
    Start from debug directory.
    So you can access file debug/test/debug.ini as
    System.getProperty( "user.dir" ) + "/test/debug.ini"
    Works?

  • Getting name or full path of  current directory via oracle

    is it possible to retrive the name of the current directory or the directory in which you are currently working.
    Is there any function to do that.
    like in vax/vms we do sh default command to see the current directory .
    If you know the answer please share it with me.

    Hi,
    If your OS is Linux/Solaris then you can issue in sqlplus something like this
    SQL> !pwd
    /export/home/oracle/dbatools.
    regards
    Jafar

  • Running a java program in a directory other than the current directory

    How do I run a java program that's located in a directory other than the current directory?
    There is a file Test.java in /dir1/subdir1. If my current directory is anywhere other than that directory, say /dir2/subdir2, I can compile Test.java by using:
    javac -classpath /dir1/subdir1 /dir1/subdir1/Test.java
    But when I try to run it with:
    java -classpath /dir1/subdir1 /dir1/subdir1/Test
    I get a java.lang.NoClassDefFoundError: \dir1\subdir1\Test
    Any thoughts?

    You need to specify just the name of the class you want to run. So java -classpath /dir1/subdir1 Test

Maybe you are looking for

  • Bluetooth A2DP streaming from Android Phone to Macbook

    Hello, Just got a MBP a while back and this is my first apple computer - doing good so far. In Windows, I was able to bluetooth connect to my Android phone and my Android phone could stream the music it was playing over to my Windows computer speaker

  • Can Macbook Air 11" (1.4 Ghz 2 GB Ram 128 GB HD) run xCode as well ?

    I've planed to buy a new portable laptop which lighter and smaller than other. I doubt,Can Macbook Air 11" (1.4 Ghz 2 GB Ram 128 GB HD) run xCode as well ? I love its design.

  • The high light tool doesn't work

    On a recently downloaded pdf file I cannot get the Highlight tool to function using Adobe Reader XI. It works fine with other pdf files on my computer. What's going on??

  • Possible to make an item editable for certain users and read only for other

    Is it possible to make an item editable for certain users and read only for others? I've been able to accomplish this by taken the select statement that I used to define an authorization scheme, placing it in the Read Only condition of the item. Howe

  • Drag Layer behavior problem in IE 6

    I have created a simple page with a draggable layer. Works fine in FF but if you scroll to the bottom of the page in IE the layer is not draggable any more. I first noticed this behavior when I created layers with DW MX2004, so just to make sure, I d