What is the absolute path of my file?

Suppose my file is at the location
C:\oc4j\j2ee\home\applications\r1\r1\WEB-INF\lib\us-english-v2-whole.dict
what is the absolute path of this file.

Congrats on 20k warner.
Of course, if you're going to try to use that path in a String literal, you'll have to escape the backslashes
String absPath = "C:\\blah...";In Java, most File I/O classes are smart enough to translate a path into one that works with your platform. So when using paths in say a File object, you can just use forward-slashes to be consistent and not have to escape them.

Similar Messages

  • How to get the absolute path of a file from the local disk given the file n

    how to get the absolute path of a file from the local disk given the file name

    // will look for the file at the current working directory
    // this is wherever you start the Java application (cound be C: and your
    // application is located in C:/myapp, but the working dir is C:/
    File file = new File("README.txt"); 
    if (file != null && file.exists())
        String absolutePath = file.getAbsolutePath();

  • To get the absolute path of a file in JSP

    Hi,
    I want to include a HTML page in a jsp.The path of the jsp should not be hot coded.So that i can get the path from the jsp file i am running and then concat the correspondinghtml file name to the absolute path of the jsp file i am running.What can i do to get the absolute path of the jsp file.

    I dont know if there is a way to get the path of the current jsp - but you sure can get the path to your web application using the ServletContext's getRealPath() method and then if you have stored the html (say x.html) in a folder (called, say 'static') immediately under your application root,
    String contextPath = application.getRealPath("/"); //path to your application ctxt
    String htmlFilePath = contextPath.append("/static/x.html");ram.

  • Function that finds the absolute path of a file

    Hi,
    I'm creating an application using the SDL framework.
    The following code gives me the absolute path for the file "caisse.jpg", which is located in my application bundle. Then, I can use the value of "cstrURL" to load the image with IMG_Load(cstrURL);
    #import <CoreFoundation/CoreFoundation.h>
    int main(int argc, char *argv[])
    CFURLRef url = CFBundleCopyResourceURL( CFBundleGetMainBundle(),
    CFSTR("caisse"),
    CFSTR("jpg"), //extension du fichier
    NULL );
    const char* cstrURL = CFStringGetCStringPtr(
    CFURLCopyFileSystemPath(url,kCFURLPOSIXPathStyle),
    CFStringGetSystemEncoding()
    printf("URL: %s", cstrURL);
    return EXIT_SUCCESS;
    But I have many files to load for my application. I tried to create a function that would take as parameter informations about the image, and then automatically find the absolute path of this image.
    ( void imgPath(char name[], char ext[], char destination[] ---> name = "image", ext = "jpg", destination is a variable in which the function puts the absolute path of the file)
    How can I do that? What bugs me is the use of the CFSTR macro in the code I have...
    Thank you very much
    FRANKY

    The CFSTR macro can only use a constant string as parameter, not a variable one.
    You can use instead CFStringCreateWithCString if the parameter is a C String (char *).
    Additionaly, I think the input parameters of your imgPath function must be of char* type, not char. And the output parameter char** (but it would be easier to know with the function source code).

  • 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.

  • Getting absolute path of a file in a webapp without using servlet/JSP

    Hi all,
    I need a small clarification. Is it possible to reterive the absolute path of a file present in a tomcat web application without using Servlet/JSP. I have a normal java class which uses this file to read the configuration parameters. I like to know whether I need to create a seperate servlet which will read the parameters from web.xml.

    Hi all,
    I need a small clarification. Is it possible to
    reterive the absolute path of a file present in a
    tomcat web application without using Servlet/JSP. What if the file is in a WAR? What do you do then?
    I
    have a normal java class which uses this file to
    read the configuration parameters. There are other, better ways to do this.
    I like to know
    whether I need to create a seperate servlet which
    will read the parameters from web.xml.What do you really want it for? You shouldn't need an absolute path. Use the class loader to get an InputStream.
    %

  • Get absolut path of a file

    when I write to a file in the actuel directory,
    e.g fw = new FileWriter("file.txt");
    how I can get the absolute path of this file? (e.g. C:\dir\file.txt)
    thanks stn

    Captain Obvious says ..... File.getAbsolutePath();
    Thank you, Captain Obvious.

  • Getting the absolute path of the current executing file

    I have a file which will be placed in window and linux environment. It is not good to change the source code in that way:
    String path = "D:\\java\file1.txt"; (Window)
    String path = "/java/file1.txt"; (Linux)
    So I would like to ask how to get the absolute path based on that executing file?
    I referred to the reference in jsp, but I don't know what class and the coding syntax in console environment.
    Thx for any help.

    If you are looking to "get" a file that is located in a directory with (or somewhere under) the class file than use
    myClass.getClass().getResource(<relativePathWithFileFromClass>);  //URL
    myClass.getClass().getResourceAsStream(<relativePathWithFileFromClass>);  //InputStreamAs far as determining which Operating System you are on, there are a number of environment variables that will tell you that, and you can then format your file path accordingly.
    You can use "/" in your path regardless of which OS you are using. You do not have to use "\\" on Windows (excpet maybe inside of a Runtime.exec command string).
    Here is a very small program you can compile and run if you wish to see the list of System Properties available:
    public class ShowProperties {
      public static void main(String[] args) {
        System.getProperties().list(System.out);
    }Just save that to a file (named ShowProperties.java of course) and compile and run it, and you will get a list of your available System Properties and their current values

  • How to find the absolute path of file  which store in KM foler ?

    Hello everyone:
         We want to develop an ABAP program which can write files into KM folder directly.
         So I need to find the absolute path of file which store in KM folder first, then we can consider the develop solution.
         Is this issue possbile that an ABAP  program write files into KM folder  directly ?
         Is there anybody had done this job ?
    Best Regards,
    Jianguo Chen

    Hi,
    http://forum.java.sun.com/thread.jsp?forum=34&thread=36
    612The methods in the above topic seem to be available when use a DOM parser..

  • Get the absolute path and filename of the file from the command line

    Hi,
    when we run the class we give the command
    java <filename>
    How can I capture the filename given above and get its absolute path inside the
    public static void main(String [] args){}
    args[0] gives me the command line argument after the filename. How do I capture the filename itself from the command line argument and also get that files absolute path
    Thanks

    I don't know of any way to capture the java command input, but there are ways to find out where the application is being run from. (the "absolute path")
    http://forum.java.sun.com/thread.jsp?forum=31&thread=335394

  • How to get the absolute path of logicalhost server domain on Windows Sun

    i am reading a file from Xsql Folder, that is located in the logicalhost Sun\AppServer\domains\domain1\applications\j2ee-apps.(IN Sun Application Server)
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    i tried with System.getProperty("com.sun.aas.instanceRoot").
    but i am able to retrive Sun\AppServer\domains\domain1 upto this .i am unable to retrive Sun\AppServer\domains\domain1\applications\j2ee-apps.
    please suggest me how u can get absolute path in sun application server

    Take a look here

  • How to get the absolute path of logicalhost server domain on Windows?

    My logicalhost server domain behaves strangely. I am reading a file from collaboration definiton, that is located in the logicalhost/is/domains/domain1/config folder. I thought, that this folder is used as an application root folder so I can read files like ./file from there. And it worked.
    But then I've installed the domain as a Windows service, restarted the PC. When the domain1 gets started, I get exceptions saying that the file can't be found. Then I restart the domain (in domainmgr.bat) and it works again.
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    And my second question is: Why does this happen?

    The default folder for a Windows Service is the system32 folder contrary to the instance root folder when starting it as a normal process.
    That's the why, haven't tried the how, but you should be able to get the value by calling System.getProperty("com.sun.aas.instanceRoot").
    Hope this helps
    Paul

  • How to get the absolute path of a DTD referenced in an XML?

    Hello!
    My OS is Windows.
    I use "org.apache.xerces.parsers.SAXParser" which implements LexicalHandler to parse XML files. When method "startDTD" starts and "systemId" is got, how can I get the absolute path? Is there any simple way?
    Regards!

    Hi,
    http://forum.java.sun.com/thread.jsp?forum=34&thread=36
    612The methods in the above topic seem to be available when use a DOM parser..

  • How to get the Real Path of a file which is accessed  by URL?

    iam using tomcat6.0.
    I have a file xyz.xml at the top of the webapplication HFUSE which i can able to access by URL
    http://localhost:8080/HFUSE/xyz.xml
    My problem is how to get the realpath of the file "xyz.xml" for reading and writing purposes.
    I tried various things but i could not able to successfully solved the problem?
    1) File f = new File("/xyz.xml");
    print(f.getAbsolutePath()) ============== it is not fetching the file @ http://localhost:8080/HFUSE/xyz.xml rather it is creating a file
    at the root of the drive where eclipse is running.
    2) File f = new File("xyz.xml");============> this is also not working , it is creating the file xyz.xml in the eclipse directory ..................
    Can anyone please guide on this problem?

    RevertInIslam wrote:
    If you want your context root(i.e HFUSE)
    use this:
    request.getContextPath() //where request is HttpServletRequest object to get the needful path.
    e.g:
    File f = new File(request.getContextPath()+"/xyz.xml");//it will create the file inside HFUSE.
    Hope this helps.
    Regards
    BWrong. The File constructor expects an absolute filesystem path. The HttpServletRequest#getContextPath() doesn't return the absolute filesystem path, it only returns the relative path from the current context root. Use ServletContext#getRealPath() instead, it returns the absolute filesystem path for the given relative path from the current context root.
    File file = new File(servletContext.getRealPath("/"), "xyz.xml");

  • Finding the exact path of a file using a Java program

    Can anyone tell me how to find the exact path of a file which is saved in a directory other than the one in which the main file is saved? I know there is a class called File which has many methods like isAbsolutePath() and isPath() but they return the path in which the main class is located

    actually i m trying to write a program which will
    take a name of a file or a directory from the console
    and it should give the entire path of that file or
    directory and this file need not be stored in the
    path of the main class.....It can be stored in any
    drives of my PC....Ok, then the console input needs to be an absolute path or a path relative to some given directory (usually the one from which the application is started). Java cannot magically guess absolute paths if you just provide a file name. E.g. if I'd use your program and would provide as input "build.xml", how should the program know which file by that name I mean (there are lots of build.xml files in different locations on my machine)?

Maybe you are looking for

  • SXI_CACHE error in PI 7.1.

    Hi All, I am getting the below error when I am doing SXI_CACHE in PI 7.1. "Error 'HTTP status code 503  Service Unavailable' while executing HTTP request (calling method 'get_status')" I have restarted the ABAP server but still facing the above error

  • Is There A Comprehensive List Of Actions Using Modifier Keys?

    I have been using Macs for nearly five years and thought I was reasonably proficient. A few minutes ago I was told that it is possible to MOVE a file from one HD to another (rather than COPY it) by holding down the Command key. I wonder how many more

  • If I sync my iPod to a new computer will I loose all my music?

    Will I loose all the stuff on my iPod if I sync it to a new computer?

  • GR based invoice verification (customising)

    Hi, Can somebody please give me the spro menu path to set this up? Anna-Marie

  • Automatic Slideshow in Keynote?

    I am working on a speech presentation for an online class.  The problem I had was, I couldn't record the slideshow with me speaking the entire 5 minutes because that was too difficult to not make any mistakes. SO, I recorded voice memos on my phone f