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

Similar Messages

  • 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 a form within the Forms

    Aslam o Alikum (Hi)
    How to get absolute path of a form within the Forms 6i or 9i
    For example
    i am running a from "abc.fmx" from C:\myfolder directory
    can i get the form path 'C:\myfolder' by calling any any function from "abc.fmb"

    There is no direct call that will always work. What you need to do is call get_application_property(current_form). This may have the full path in it, depending on if that path was defined when the form was launched. If there is no path, then you need to use TOOL_ENV.GETVAR to read the Forms<nn>PATH and the ORACLEPATH, parse those out into individual directories and then check for the FMX in each.
    I already have some code to do all this for you see:
    http://www.groundside.com/blog/content/DuncanMills/Oracle+Forms/?permalink=4A389E73AE26506826E9BED9155D2097.txt

  • Absolute path of current directory?

    Hi,
    I finished up an assignment the other day. But I've been playing around with it to see how much
    extra junk, in addition to the requirements, I can add, all in one method(we haven't covered
    user defined methods yet). I added a cheezy console splash screen. A really cheezy help file
    system. Figured out how to add time and date stamps. And some code to allow the user to
    continue the program and generate multiple reports with unique filenames. I added some
    input validation, user has to enter the name of a database to sample. All the files are plain text.
    What I'm trying to do is, add a better validation system so the program doesn't terminate if the
    user enters a database name that isn't in the directory. All the files will be in the directory where
    the program resides, so that eliminates some headaches.
    I was thinking of doing it like this: when a user enters a name check to see if the name is on the list
    (I guess java is already doing this that why the error is generated)
    if not, output error message and print the valid list to standard out. Prompt user to re enter a
    valid name.
    I'm sure there are more sophistcated ways to do this but I'm trying to work with what I kinda know.
    So far I've managed to figure out how to list the files in the program's home directory. By
    using the dir's absolute path on my machine. But this wont work on another computer. I'm
    pretty sure I can figure out how to add a filter so only certain file types will be listed.
    Is there a way to have the program get the absolute path of the program's directory no
    matter what computer it is on??
    I could go from there pretty easily, I'm hoping.
    Thanks for any direction,
    bill

    ooops... That is not working quite right.What is not working and how?Actually I did get some good results.
    Here is the code I came up with over the last hour or so.
    String curDir = System.getProperty("user.dir");
             System.out.println(curDir);
              File dir = new File(curDir);
                  String[] children = dir.list();
                  if (children == null) {
                  } else {
                      for (int i=0; i<children.length; i++) {
                          String filename = children;
              if(filename.length()<20&&filename.charAt(0)!='.')
              System.out.println(filename);
    This seems to work OK. It identifies and stores the path
    of the directory where java was invoked. And prints to the console
    a listing of available files to choose from. I trying to figure out
    how to better filter the in/output to hide the .java and .class files.
    Tonight I'm really just having fun
    googling, cutting, pasting, modifing snippetts to see if I can make my
    computer do what I want it to. I'm very new at this, just my way of
    learning stuff out of the class room.
    Thanks again,
    if you have any tips, I sure would appreciate it.
    Bill

  • How to get physical path of current working file?

    I WANT TO KNOW THE PHYSICAL PATH OF CURRENT WORKING FILE IN JAVA ON BOTH UNIX AND WINDOWS PLATFORM.
    HOW TO GET IT?
    THANK U

    I am not sure this is the correct way to do it, but I tried it out a bit and found that the following will work (that is, I tested it on NT :-)):
    String nameWithPackage = YourClass.class.getName();
    String name = (nameWithPackage.substring(nameWithPackage.lastIndexOf(".")+1))+".class";
    URL url = YourClass.class.getResource(name);
    String path = url.getPath();I hope this will help...

  • Getting absolute path of webapps directory

    Hi,
    Using a Tomcat server, i would like to get the absolute path of the Tomcat/webapps/ directory in one of my JSP pages, without using functions related to Servlet context...is it possible?
    In fact my real problem is that i want to open an existing text file in my JSP page. To do so i need the absolute path of it. This file must also be stored in Tomcat/webapps.
    Can anybody help me? i've search the forum and found some others topics like this one but didn't find my answers.
    Thanks

    Hi,
    Using a Tomcat server, i would like to get the
    absolute path of the Tomcat/webapps/ directory in one
    of my JSP pages, without using functions related to
    Servlet context...is it possible?
    Any specific reason for not using ServletContext's getRealPath() method ?
    In fact my real problem is that i want to open an
    existing text file in my JSP page. To do so i need
    the absolute path of it. This file must also be
    stored in Tomcat/webapps.Hmm,, file i/o is evil. You could use the methods of Class and ClassLoader to read in the file as a stream. The only requirement is that they be in the classpath.
    More info here - http://www.javaworld.com/javaqa/2003-08/01-qa-0808-property_p.html
    cheers,
    ram.

  • How can I get the server absolute path of virtual directory?

    Problem context:
    absolute path of my application at JRUN server is
    c:\testing
    nd url is
    http://kaspak/test
    ( kaspak is a machine local to server i-e client nd server r at same machine )
    I m uploading a file nd saving it at server.
    PROBLEM:
    server save my uploaded file at
    C:\Program Files\Allaire\JRun\servers\default
    [ a path where server is installed ]
    while I want to save it at directory
    c:\testing\uploadfiles
    How can I achieve this???
    waiting for quick reply..
    KasPak

    here is a function for which u said,
    protected void readAndSaveFile(MultipartInputStreamHandler in,
    String boundary,
    String filename,
    String contentType) throws IOException
    A utility method that reads a single part of the multipart request that represents a file, and saves the file to the given directory. A subclass can override this method for a better optimized or differently behaved implementation.
    again saving a file, or uploading a file is no problem,
    but saving a file at our desired location,
    nd this can only be done if we know reall/absolute path of our application at server,
    i-e we need an API which can tells the absolute path of our application.
    e.g
    our application url is http://kaspak/testcode
    we need its absolute mapping to directory on server
    e.g it it is at c:\testcode
    if we get the absolute path then we can pass it in above function or in File class constructor.
    isn't it??
    I think in this way i can save file at other location.
    But how i can get absolute path?????
    thanks for ur reply,
    nd waiting for ur reply again.
    wbw
    kaspak

  • How to get the path when i select a directory or a file in a JTree

    How to get the path when i select a directory or a file in a JTree

    import java.lang.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.HeadlessException;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Iterator;
    * @author Frederic FOURGEOT
    * @version 1.0
    public class JTreeFolder extends JPanel {
    protected DefaultMutableTreeNode racine;
    JTree tree;
    protected JScrollPane scrollpane;
    final static int MAX_LEVEL = 1; // niveau max de descente "direct" dans l'arborescence
    * Sous-classe FSNode
    * @author Frederic FOURGEOT
    * @version 1.0
    private class FSNode extends DefaultMutableTreeNode {
    File file; // contient le fichier li� au noeud
    * Constructeur non visible
    private FSNode() {
    super();
    * Constructeur par initialisation
    * @param userObject Object
    FSNode(Object userObject) {
    super(userObject);
    * Constructeur par initialisation
    * @param userObject Object
    * @param newFile File
    FSNode(Object userObject, File newFile) {
    super(userObject);
    file = newFile;
    * Definit le fichier lie au noeud
    * @param newFile File
    public void setFile(File newFile) {
    file = newFile;
    * Renvoi le fichier lie au noeud
    * @return File
    public File getFile() {
    return file;
    public JTree getJTree(){
         return tree ;
    * Constructeur
    * @throws HeadlessException
    public JTreeFolder() throws HeadlessException {
    File[] drive;
    tree = new JTree();
    // cr�ation du noeud sup�rieur
    racine = new DefaultMutableTreeNode("Poste de travail");
    // cr�ation d'un noeud pour chaque lecteur
    drive = File.listRoots();
    for (int i = 0 ; i < drive.length ; i++) {
    FSNode node = new FSNode(drive, drive[i]);
    addFolder(drive[i], node); // on descend dans l'arborescence du lecteur jusqu'� MAX_LEVEL
    racine.add(node);
    // Gestion d'evenement sur JTree (on �coute les evenements TreeExpansion)
    tree.addTreeExpansionListener(new TreeExpansionListener() {
    public void treeExpanded(TreeExpansionEvent e) {
    // lorsqu'un noeud est ouvert
    // on descend dans l'arborescence du noeud jusqu'� MAX_LEVEL
    TreePath path = e.getPath();
    FSNode node = (FSNode)path.getLastPathComponent();
    addFolder(node);
    ((DefaultTreeModel)tree.getModel()).reload(node); // on recharche uniquement le noeud
    public void treeCollapsed(TreeExpansionEvent e) {
    // lorsqu'un noeud est referm�
    //RIEN
    // alimentation du JTree
    DefaultTreeModel model = new DefaultTreeModel(racine);
    tree.setModel(model);
         setLayout(null);
    // ajout du JTree au formulaire
    tree.setBounds(0, 0, 240, 290);
    scrollpane = new JScrollPane(tree);
         add(scrollpane);
         scrollpane.setBounds(0, 0, 240, 290);
    * Recuperation des sous-elements d'un repertoire
    * @param driveOrDir
    * @param node
    public void addFolder(File driveOrDir, DefaultMutableTreeNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    addFolder(driveOrDir, node, 0);
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Recuperation des sous-elements d'un repertoire
    * (avec niveau pour r�cursivit� et arr�t sur MAX_LEVEL)
    * @param driveOrDir File
    * @param node DefaultMutableTreeNode
    * @param level int
    private void addFolder(File driveOrDir, DefaultMutableTreeNode node, int level) {
    File[] fileList;
    fileList = driveOrDir.listFiles();
    if (fileList != null) {
    sortFiles(fileList); // on tri les elements
    // on ne cherche pas plus loin que le niveau maximal d�finit
    if (level > MAX_LEVEL - 1) {return;}
    // pour chaque �l�ment
    try {
    for (int i = 0; i < fileList.length; i++) {
    // en fonction du type d'�l�ment
    if (fileList[i].isDirectory()) {
    // si c'est un r�pertoire on cr�� un nouveau noeud
    FSNode dir = new FSNode(fileList[i].getName(), fileList[i]);
    node.add(dir);
    // on recherche les �l�ments (r�cursivit�)
    addFolder(fileList[i], dir, ++level);
    if (fileList[i].isFile()) {
    // si c'est un fichier on ajoute l'�l�ment au noeud
    node.add(new FSNode(fileList[i].getName(), fileList[i]));
    catch (NullPointerException e) {
    // rien
    * Recuperation des sous-elements d'un noeud
    * @param node
    public void addFolder(FSNode node) {
    setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
    for (int i = 0 ; i < node.getChildCount() ; i++) {
    addFolder(((FSNode)node.getChildAt(i)).getFile(), (FSNode)node.getChildAt(i));
    setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
    * Tri une liste de fichier
    * @param listFile
    public void sortFiles(File[] listFile) {
    triRapide(listFile, 0, listFile.length - 1);
    * QuickSort : Partition
    * @param listFile
    * @param deb
    * @param fin
    * @return
    private int partition(File[] listFile, int deb, int fin) {
    int compt = deb;
    File pivot = listFile[deb];
    int i = deb - 1;
    int j = fin + 1;
    while (true) {
    do {
    j--;
    } while (listFile[j].getName().compareToIgnoreCase(pivot.getName()) > 0);
    do {
    i++;
    } while (listFile[i].getName().compareToIgnoreCase(pivot.getName()) < 0);
    if (i < j) {
    echanger(listFile, i, j);
    } else {
    return j;
    * Tri rapide : quick sort
    * @param listFile
    * @param deb
    * @param fin
    private void triRapide(File[] listFile, int deb, int fin) {
    if (deb < fin) {
    int positionPivot = partition(listFile, deb, fin);
    triRapide(listFile, deb, positionPivot);
    triRapide(listFile, positionPivot + 1, fin);
    * QuickSort : echanger
    * @param listFile
    * @param posa
    * @param posb
    private void echanger(File[] listFile, int posa, int posb) {
    File tmpFile = listFile[posa];
    listFile[posa] = listFile[posb];
    listFile[posb] = tmpFile;

  • How to get cwd of the current process in the kernel in Solaris 8

    Hi, everyone
    Does any one know how to get the path name of the current working directory of the current process in the kernel in Solaris8 ?
    I searched the forum and got some related links, but none of them gives a clear solution.
    Sample code can help a lot!
    Thank you!

    NiuLin wrote:
    Thanks for the reply.
    What the user structure contains is the vnode pointer of the cwd, but I want go get the pathname of it, like /export/home/abc/.First, all you can get is a path name - there can be more than one. And then there's the problem of determining the path name you want if the process is running under chroot.
    Assuming you don't have to deal with those, there's this thread:
    http://forum.java.sun.com/thread.jspa?threadID=5084620&messageID=9298124
    Of course, that thread doesn't say how to do that. But it appears to be part of Solaris 10.
    I once had to solve this same problem for a Linux kernel module I wrote, so I know it's theoretically possible. But I also know it's not as simple as it seems it should be, and any results you do get are not guaranteed to be unique and, IIRC, not even correct in some cases.
    Sorry I can't be more specific than that right now.

  • How to get absolute in servlet

    how to get absolute in servlet like c:\temp\apache group\tomcat4.1\test\abc.gif, thanks

    do sthing like:
    getServletContext().getRealPath("/abc.gif") in any servlet in 'test' to get the real path of abc.gif - The parameter should be relative to the current context

  • How to create a file in current directory

    hi,
    I want to create a file in a current directory, But when i written following
    code then it cannot create file, How i will create file in current directory?
    Is there anyone who can help me?what will be the solution of this problem?
    Please give me solution
    String dir=application.getRealPath("/");
         int count;
         String filename="sample.txt";
         out.println(dir+filename);
         FileOutputStream fout=new FileOutputStream(filename);
         PrintStream p;
         p=new PrintStream(fout);
         p.print("1");
         p.close();with regards
    Bina

    hi,
    my problem is that my path is ok...but when i open file in this directory then
    it cannot open a file, is there anyone who can do it? When a user save data in server from remote
    area then what will be path of my code? how i will solve it? please give me
    solution.
    with regards
    bina

  • Getting absolute path of a file running in remote machine

    Hi,
    I want to get the absolute path of a file that will be created in the remote server. Inside a directory XYZ in remote machine, the file will be created and the remote machine's address is xxx.xx.x.x. I have used the following snippet
    File f=new File(Filename);
    f.getAbsolutePath();
    Now, in the output am getting the absolute path of the file as d:/XYZ/Filename. Is there any way to get the output as xxx.xx.x.x/XYZ/FileName ? Can someone please suggest why the server details are not fetched and instead the directory name is fetched.
    I am running the program to get absolute path of a file in my remote machine. and for accessing that remote file from my machine, I use xxx.xx.x.x/XYZ/FileName.
    Thanks in advance.

    I'm going to take it a step further and guess at what the OP is going to say next.
    On host w.x.y.z there's a file /a/b/share/some_dir/file.txt.
    Host w.x.y.z is sharing the /a/b/share/ directory as SHARE.
    Client mounts \\w.x.y.z\SHARE as D:, so that he sees D:/some_dir/file.txt.
    OP now wants to know not just that D:/some_dir/file.txt is \\w.x.y.z\SHARE/some_dir/file.txt, but also wants to know that on w.x.y.z, SHARE corresponds to /a/b/share.
    @OP: If that's what you want, forget it. Part of the premise of file common drive/directory sharing protocols is that the client does not know or care and does not need to know or care what the absolute path is on the serving host. It's none of his business.

  • How to get the Path of the WebDynpro page

    Hi All,
    Can any one say how to get the path of the JSPDynPage ina Portlet in Portal Application.
    Becoz i have to display that Page in another JSPDynPagee
    Thanks in Advance....

    Hi,
    You can call your JSPDynPage component by calling the URL as:
    http://localhost:50000/irj/servlet/prt/portal/prtroot/YourApplicationName.YourComponentName
    Check this:
    Calling portal component
    Greetings,
    Praveen Gudapati
    [Points are welcome for helpful answers]

  • How to get the path of the image stored in sap??

    Hi All
    The problem is
    While making an entry in standard there is a field called documents through which we attach our images in sap.
    How to get the path of the image stored with the corresponding order so that the image can be displayed while we are creating a report.
    I know how to upload the image while creating a report using docking control.
    I am not able to get the path of the image stored...
    Please Help
    Thanks in advance..
    Pooja

    I am not aware of exactly which tables are used for storing the attached doc. details, but we have worked in the similar requiremnent.
    What you can do is .... before uploading the image to any order, try swich on the SQL trace ST05 and after upload switch off.
    The log will display what are the tables involved while storing the image. And you can easily find out the image location.

  • How 2 get the path of a file

    how 2 get the path of a file Using jsp
    i have tried getPath...but i'm geting the error
    The method getPath(String) is undefined for the type HttpServletRequest
    any idea how 2 get the path of a file

    You need ServletContext#getRealPath().
    API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

Maybe you are looking for

  • After I downloaded Maverick my tabs have went to a smaller font and can't get them back.

    After i downloaded new Mavericks operating system I've had problems. The first one is fonts on menu tabs changed to a very samll size and i can't figure out hiw to increase the size. We have had the Mac a couple of years now but I still haven't caugh

  • BPM Task Flow

    Hi , I created a BPM application which has a human task in the BPM flow. This task takes a parameter (requestor id) and sends an email to this requestor to submit a form.Data enetered should be saved in the database. How can i achieve this? Thanks, L

  • Billing Information "None" option

    Hello, I am trying to download a free application using my Apple Id and the password but in the Billing Information step, there is no "None" option and I do not have a credit card. What can I do ? Thank You in advance.

  • VISA get resource name doesn't return USB serial ports

    We built an application on a computer that had an onboard serial port - COM1.  We put the option to change the COM port in the application.  We installed the built application on a computer with no serial ports, but installed a USB to serial converte

  • Mighty mouse and windows 7

    hi i have a mighty mouse and i had it working on a sony vaio laptop with windows 7 installed , i had to remove it for mac computer, have tried reinstalling it on the sony again but it will not be recognized can anyone help please