How to find the physical path of a file

Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
Your solution is welcome.
YC

Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
Your solution is welcome.
YC

Similar Messages

  • How to find the physical path of the ASM disks?

    I am in a dilemma on how to find out the physical path of the ASM disks. I tried the following query, but as you can see it is not providing me the physical path of the LUN. This is a 2 node 10.2.0.4 RAC Cluster using asmlib package.
    col name format a20
    col path format a20
    col label format a20
    select name, path, label from v$asm_disk;
    NAME PATH LABEL
    ORCL:ASM103 ASM103
    ORCL:ASM104 ASM104
    ORCL:ASM117 ASM117
    ASM101 ORCL:ASM101 ASM101
    ASM102 ORCL:ASM102 ASM102
    ASM105 ORCL:ASM105 ASM105
    ASM106 ORCL:ASM106 ASM106
    ASM107 ORCL:ASM107 ASM107
    ASM108 ORCL:ASM108 ASM108
    ASM109 ORCL:ASM109 ASM109
    ASM110 ORCL:ASM110 ASM110
    NAME PATH LABEL
    ASM111 ORCL:ASM111 ASM111
    ASM112 ORCL:ASM112 ASM112
    ASM113 ORCL:ASM113 ASM113
    ASM114 ORCL:ASM114 ASM114
    ASM115 ORCL:ASM115 ASM115
    ASM118 ORCL:ASM118 ASM118
    ASM119 ORCL:ASM119 ASM119
    ASM120 ORCL:ASM120 ASM120
    ASM121 ORCL:ASM121 ASM121
    ASM122 ORCL:ASM122 ASM122
    ASM123 ORCL:ASM123 ASM123
    NAME PATH LABEL
    ASM124 ORCL:ASM124 ASM124
    ASM125 ORCL:ASM125 ASM125
    ASM126 ORCL:ASM126 ASM126
    ASM127 ORCL:ASM127 ASM127
    ASM302 ORCL:ASM302 ASM302
    ASM303 ORCL:ASM303 ASM303
    ASM304 ORCL:ASM304 ASM304
    ASM305 ORCL:ASM305 ASM305
    ASM306 ORCL:ASM306 ASM306
    ASM307 ORCL:ASM307 ASM307
    32 rows selected.
    Any help will be appreciated.
    --MM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    hi
    use the following linux command as root:
    $oracleasm listdisks
    hth

  • Finding the physical path of a file

    I'm developing a JSP webapp on www.mycgiserver.com and I need to open a XML file....but the standard method of
    ServletContext sc = getServletConfig().getServletContext();
    String realPath = sc.getRealPath("data\\repositoryData.xml");
    seems not to work. It gives me
    Real Path of data\repositoryData.xml: /usr/local/resin/doc/data/repositoryData.xml
    Which ends up giving me null pointer exceptions on my Document objects. I assume that means it's not finding any file at that location. What am I doing wrong?

    try:
    String rootContext = getServletContext().getRealPath();
    String servletPath = request.getServletPath();
    realPath = rootContext + servletPath //however, it's what ever the servlet-mapping element
    in your deployment descriptor is set too

  • 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)?

  • 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();

  • How to find the menu path ?

    Hi all,
    I have one doubt how do we find out the correct menupath if we know the t-code ?
    for example, SE11 -DDIC
    we can also obtain the same DDIC screen via menupath from SAP main screen.
    if I know only t-code.how can i find out the menupath ?
    thnks and rgds,
    raghul

    Hi Raghul,
      You can go to the transaction search_sap_menu
    for finding the menu path.
    check this link:
    http://www.sap-basis-abap.com/sapgeneral/system-path-and-transaction-code-mapping.htm
    Hope this helps you.
    Regards,
    Chandra Sekhar

  • How to find the tomcat path from registry?

    Hi,
    How can I find the tomcat path from registry?
    please tell me.
    Thanks
    Gaurav Agrawal

    gauravjlj wrote:
    listen,
    I'm about to create a exe which will do these things.....
    1. first install java
    2. install tomcat
    3. install mysql
    4. deploy my web application with out use of tomcat manager
    first three steps I have done with the help of installer maker. let assume that my tomcat has been installed. but now please tell me how can I deploy my web application.
    that's why I need the tomcat path.
    please tell me.Well, if you've just installed Tomcat you do know where it is so what's the problem? Why not, in fact, include your application in the tomcat directories as you install them? That's all there is to installing tomcat, installing the directories, setting %JAVA_HOME% and (possibly) running the service.bat file.

  • How to get the physical path of my web app root context ?

    Hi,
    I used this code to initialize my LOG4J logger.
            System.out.println(Version + "Servlet context path : " + sctx .getContextPath());
            String path = sctx .getRealPath("/");
            fullyqualifiedlog4jpath = path + "log4j.xml";
            File locallogxml = new File(fullyqualifiedlog4jpath);
            if (locallogxml.exists()) {
                initialized = true;
                DOMConfigurator.configure(fullyqualifiedlog4jpath);
                log = Logger.getLogger(Log4j.class.getName());
                log.info(Version + "Logger initialized");
            else {
                System.out.println(Version + "Unable to locate the log4j.xml file");
            }It works perfectly when running the application with the embedded Jdev11 WLS.
    When deploying the application on a standalone WLS server the path is not returned ;-( I get a null value.
    Does someone has three lines of code which get the physical path of my web app root context?
    Yves

    Changed the methiod used to access log4j.xml.
            FacesContext ctx = FacesContext.getCurrentInstance();
            ServletContext sctx = (ServletContext) ctx.getExternalContext().getContext();
            String contextPath = sctx.getContextPath();
            HttpServletRequest  hsr = (HttpServletRequest)ctx.getExternalContext().getRequest();
            String host = hsr.getServerName();
            int port = hsr.getServerPort();
            try
              String urlstring = "http://" + host + ":" + port + contextPath + "/faces/log4j.xml";
              DOMConfigurator.configure(new URL(urlstring));
              log = Logger.getLogger(Log4j.class.getName());
    .....using the URL s OK.

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

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

  • 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");

  • How to display the physical location of my file ?

    I got to display the physical lacation of a file in my HDD in a textbox. I'am using 'fileChooser' to get access to the HDD. Is there a method i can use in fileChooser which will display the path to the file?
    thanks

    getSelectedFile().getAbsolutePath()
    http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
    http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html
    -Puce

  • How to find the previous path environment variable in windows 2008

    I am reconfiguring the Hyperion 11.1.2, and later, I installed the ODI. And them when I come back to reconfigure the Hyperion, it cannot be reconfigured, and say cannot find the path parameter. And I check the PATH environment variable, and find it is showing a dumy value, do we have a way to recover the previous PATH envirnment variable?

    To get the source IP address, you will need to enable File Share auditing: http://technet.microsoft.com/en-us/library/dd772690%28v=ws.10%29.aspx
    Otherwise, you can simply disconnect the user session.
    This posting is provided AS IS with no warranties or guarantees , and confers no rights.
    Ahmed MALEK
    My Website Link
    My Linkedin Profile
    My MVP Profile

  • How to find the location of java class files at runtime?

    Does anyonw have an idea how to get the file name of a java class given the binary name?
    I mean how can I get the file name for my class myPackage.myClass?
    I am looking for a function which takes "myPackage.myClass" as input and returns
    "c:\\javaprojects\\myPackage\\myClass.class".
    I tried to do it with the LassLoader class but it did not work. Does anyone have an idea if the Java core API already has a function which does that?
    Thanks, Bernhard

    Hi ,
    It is a simple SAMPLE code , you think and build a logics to handle all classes.
    Try this sample, It doesn't handle the inner classes you put logic to handle the logics for inner classes.
    The inner class format is it contains the character $ in the File location but inside the code you put "." instedad of "$" you to find out or put trials.
    package pkg1;
    import java.io.* ;
    import java.util.* ;
    import java.util.zip.* ;
    public class ClsB {
         private static Vector clsPaths ;
         public static Vector getPaths() {
              if( clsPaths == null ) {
                   String paths = System.getProperty( "java.class.path" ) ;
                   // In linux or solarise use the following
                   // StringTokenizer st = new StringTokenizer( paths , ":\n" ) ;
                   StringTokenizer st = new StringTokenizer( paths , ";\n" ) ;
                   clsPaths = new Vector() ;
                   while( st.hasMoreTokens() ) {
                        String path = st.nextToken() ;
                        File f = new File( path ) ;
                        if( f.exists() ) {
                             try {
                                  f = f.getCanonicalFile() ;
                                  clsPaths.add( f ) ;
                             }catch( IOException ioe ) { }
              return clsPaths ;
         public static String findClassPath( String fullClassName ) {
              Vector v = getPaths() ;
              for( int i = 0 ; i < v.size() ; i++ ) {
                   File f = ( File ) v.get( i ) ;
                   String path = findIn( f , fullClassName ) ;
                   if( path != null )
                        return path ;
              return null ;
         static boolean isJar( File jar ) {
              if( jar.isDirectory() )
                   return false ;
              try {
                   ZipFile zf = new ZipFile( jar ) ;
                   return true ;
              } catch ( ZipException ze ) {
                   // It is not a jar file
                   // you handle this
              } catch ( IOException ioe ) {
                   ioe.printStackTrace() ;
              return false ;
         static String findIn( File dirOrJar , String clsName ) {
              if( isJar( dirOrJar ) ) {
                   // It is something different because the class inside the jar file
                   // Simply I return the jar file location and the entry name ,
                   // but you put action what you want
                   if( isInsideJar( dirOrJar , clsName ) ) {
                        // All archieve file using the path separator is '/'
                        return dirOrJar.getPath() + "!" + clsName.replace( '.' , '/' ) + ".class" ;
              } else {
                   File f = new File( dirOrJar , clsName.replace( '.' , File.separatorChar ) + ".class" ) ;
                   if( f.exists() ) {
                        return f.getPath() ;
              return null ;
         static boolean isInsideJar( File jar , String clsName ) {
              try {
                   ZipFile zf = new ZipFile( jar ) ;
                   // All archieve file using the path separator is '/'
                   ZipEntry ze = zf.getEntry( clsName.replace( '.' , '/' ) + ".class" );
                   return ( ze != null ) ;
              } catch ( ZipException ze ) {
                   ze.printStackTrace() ;
              } catch ( IOException ioe ) {
                   ioe.printStackTrace() ;
              return false ;
         public static void main(String[] args) {
              System.out.println( findClassPath( "pkg1.ClsB" ) );
              System.out.println( findClassPath( "pkg1.pkg2.ClsA" ) );
    }

  • How to get the actual path of a file present in the Web content folder

    I have a jasper file which is present inside the Web-Content folder of my project.
    I need to pass this file as an argument to the FileInputStream object. How can i give the actual path of the jasper file, since this project can be deployed anywhere else also.

    You may be able to use the getRealPath or getResource methods in ServletContext

Maybe you are looking for

  • Burning issues with itunes and Windows Vista Ultimate

    I recently purchased a new computer with Windows Vista Ultimate 64 bit version. Since loading itunes on my new computer I can not burn a CD. The message that I receive says that there is no burner available. I know the burner works because I have bur

  • Some urgent help needed with MobileMe suddenly saying my password is wrong

    Hi First of all I want to say sorry if this is in the wrong forum, but I needed some urgent help and I couldn't find a forum other than this that might relate to this issue. The issue that I am having is with my MobileMe Account. I was on my Mac, whe

  • How to swap column-data along with Table header

    Hi All! I found a smple JTableDemo.java class. When I run it it provided sorting on the table as well as Dragging Column-data along with Table header while swaping two columns-headers. I designed my own table and apply some changes to TableModel. Aft

  • Problem using CLOB in JDBC (NewLOBAPISample)

    I've just tried to run the JDBC NewLOBAPISample, and everything works fine until I try to insert or update on the CLOB column using any characters other than base ASCII. For example, if I attempt to insert the String "$100", it works just fine, but "

  • Quarter in discoverer

    Hello People , i did tabular layout and display Quarter values for a years , some time the year come with 2 quarters because the othe values there are not values like Year|Quarter|Mark 1992|Q1|4 1992|Q2|5 1992|Q3|3 1992|Q4|2 1993|Q1|10 1993|Q2|2 1993