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

Similar Messages

  • 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

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

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

  • Where can I find the physical files of APEX_APPLICATION_FILES

    Dear The Expert,
    I got list of files from "SELECT id,name FROM APEX_APPLICATION_FILES"
    1605213787030003     F1761593527/f101.sql
    1605004091027283     F928641689/f101.sql
    1686620894182663     F1237766750/Doc1.rtf
    1687611599284065     F1530590835/blebul1a.gif
    1609417775069075     F1328258633/lippologo1.jpg
    1685122925154852     F199693486/Doc1.rtf
    1682930319090730     F1852805503/SQLAnywhere12_Full.exe
    1683026294099067     F796050035/New Text Document.txt
    1683131489100554     F823097404/New Text Document.txt
    1683316167115060     F747145779/Product List.rtf
    where can I find the physical files ? .. does it also delete the physical files if I run "DELETE FROM APEX_APPLICATION_FILES WHERE ID = '1682930319090730' ?
    please advise
    thanks & regards
    Luc

    Hi Luc,
    APEX does not create physical file that is in APEX_APPLICATION_FILES table.
    It can only store the file in BLOB format in repository.
    So when we upload file APEX stores file in BLOB column of APEX_APPLICATION_FILES table and then use when needed but no physical file.
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

  • LSMW: Error concerning the logical path in Specify Files step

    Hi,
    I am trying on an ECC 6.0 EHP6 system to upload (open) POs from an existing SAP ERP system. Since I faced some complications in batch input recording method, I decided to go with the standard batch/direct input method.
    I selected object 0085 (Purchase Order) and method 0001 (Purchase Order). The program that is used is RM06EEI0. I followed all the usual steps, but in the "Specify Files" step I get the message:
    '****.lsmw.conv' does not exist; edit the logical path using transaction FILE
    Being aware of both the FILE and SF01 transactions, I created the logical path and file (through the FILE transaction). However, after the modification, I get the message:
    Logical file '****' is not assigned to physical file '****.lsmw.conv'
    There is also the related SAP Note 753511 (Logical and physical path and file name in transaction LSMW) that refers to this case.

    Hi,
    Click on specify file radio button>Legacy data-on the PC Front end
    where input file location like C:\mydocument\desktop\test.txt
    and give input in Name field: mydocument
    in delimiter section > select Tabular
    File structure section> tick on Field order matches source structure definition
    File type: Record end marker(Text file)
    then press enter key and other steps as same.
    Second thing you said that you have used Batch input recording
    after creation and recording finish , scroll the page below on recording and put a cursor unwanted field and remove unwanted input field.
    I hope your problem will resolve. you can find the steps pdf on Google search try now.
    Thanks
    Sanjeet Kumar

  • Finding the logical path

    How to find the logical filename for the given ARCHIVE object.
    I want to know the logical file name of FI_FICA object.
    Can any one guide me.
    Thanks,
    Shree

    Hi Sree,
    I don't have SAP system right now to check it.
    I think if you know the physical path, logical path can be found.
    Please check this thread for further reference.
    https://forums.sdn.sap.com/post!reply.jspa?messageID=5726662
    Thanks and Regards,
    Guru

  • Server.MapPath(virtualPath) Returns root directory of controller, it is nor returns the physical path mentioned in the virtual directory in IIS

    I have created a virtual directory "myVirtualFile" virtual path is "\myVirtualFile" and I have given physical path as "D:\Home\myProject\Files"
    Below is my code
    var virtualpath="/myVirtualFile\UserManual";
    var resultPath=Server.MapPath(virtualpath);
    out put is resultPath contains "D:\Home\myProject\Web\client\myVirtualFile\UserManual" Expected out put is "D:\Home\myProject\Files".
    It returns the folder structure of my project. I didn't return the physical path which I mentioned in virtual directory.

    Hi,
    I am not expert on Asp.Net. But I will try my best.
    The following sample is what are
    Virtual paths and Physical paths
    ASP.NET the "~" tilde indicates the root of a virtual path.
    Virtual paths
    ~/App_Data/Sample.xml
    ~/
    ~/Map.txt
    Physical paths
    C:\Website\Files\Sample.xml
    C:\Website\Default.aspx
    C:\Website\Map.txt
    Server.MapPath doesn't find automatically where a file is. It allows to get the physical path
    corresponding to a virtual path (relative to the current request if you don't give an absolute path)
    If above still cannot resolve your issue, please repost in Asp.Net forum, The link as above posted.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I find the real path to servlet class

    Hi,
    I am facing an issue. Am in the process of creating a filter which would send a Last-modified along with the header. For this I will be checking the is-modified-since
    header and lastModified date of the file.
    The problem I am facing is that after taking the file part from the request and checking
    the lastmodified date, it gives error. This is because i use,
    String real_path = getServletContext().getRealPath(request.getServletPath());
    and it would return the path to servlet-name and not to servlet-class, since servlet-name
    is not physically present. It would return an error value.
    Is there any way which I could find the real path to my servlet class file ?

    Remember you should not take the last mnodified date
    of the class file or the jar file that contain the
    class as the value for the getLastModified method
    becouse the last modified date that should be used in
    the caching is the last modified date of the dynamic
    content that the servlet is about to prodice.
    The same class file will produce different content
    for different requests if not why do you use
    servlets you can directly use the static contentThanks for a valuable remark.
    Hence our getLastModified() often returns System.currentTimeMillis() result.

  • "Could not find the application that created this file" error when trying to combine files

    I am working with a user that is trying to combine a pdf & word doc (docx).  When they try to combine the files she gets the error:  "Could not find the application that created this file" & "Please select a file created by an application that resides on your computer".  The computer is running windows XP, with office 2010 SP1, & Adobe Acrobat Pro X.
    Per previous suggestions, I have already checked to see if Adobe PDFMaker is enabled as a Word plugin, and it is.
    Recentley the user was running Acrobat 6, and this error did not occur.  It is only after upgrading to Acrobat X that this is happening.  Any help with this issue would be appreciated.

    This can also be caused if the files are in a folder deep in the file system. For example C:/xxxxxxxxxxxxxxx/yyyyyyyyyyyyyyy/zzzzzzz/aaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbb /cccccccccccccccccccc/dddddddddddddddd/eeeeeeeeeeeeeeeeeeee/ffffffff/ggggggg/hhhhhhhhhhhhh hhhhhhhhhh/myPDF.pdf
    At some point Adobe PDFMaker cannot handle the path length (also, Windows can't handle the path length either eventually)
    Solution: move the files to a shorther path (perhaps the desktop) and try from there.
    I am filing a bug report with Adobe. A descriptive exception message should be thrown instead of "could not file the app.."

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

  • Regarding assignment of physical path to logical file name

    Hi All,
    We have created one logical file name and assigned physical path to it in FILE tcode.
    IN PATH table also these details got updated with correct logical file name & physical path.
    But in my program when i have used FILE_GET_NAME F.M to retrieve physical path from logical file.
    Here this F.M is not returning anything.
    What is the issue over here.
    We are working in ECC 6.0
    Can anybody resolve this issue!
    Thanks,
    Deep.

    do one thing i give my report so according to do this
    *& Report ZMIO_MANU_VENDOR_EXTR
    report zmio_manu_vendor_extr.
    DATA BASE TABLES
    tables: lfa1 ,eina, lfm1 .
    STRUCTURES
    *---structure for the vendor details.
    data: begin of ws_lfa1 ,
    lifnr type lfa1-lifnr,
    name1 type lfa1-name1,
    end of ws_lfa1 .
    *---structure for the pur org details.
    data: begin of ws_lfm1 ,
    lifnr type lfm1-lifnr,
    kalsk type lfm1-kalsk,
    minbw type lfm1-minbw,
    end of ws_lfm1 .
    *---structure for the pur inf rec.
    data: begin of ws_eina,
    lifnr type eina-lifnr,
    relif type eina-relif,
    end of ws_eina .
    *--structure for the output file
    data: begin of ws_final,
    lifnr(10) type c,
    name1(35) type c,
    kalsk(1) type c,
    minbw(13) type c,
    eoln(1) type c,
    end of ws_final .
    INTERNAL TABLES
    *---internal table for vendor details
    data:i_lfa1 like ws_lfa1 occurs 0.
    *---internal table for pur org details
    data:i_lfm1 like ws_lfm1 occurs 0.
    *---internal table for pur inf details
    data:i_eina like ws_eina occurs 0.
    *---internal table for final file output
    data:i_final like ws_final occurs 0.
    *DATA : P_FLAG(1) TYPE C.
    CONSTANTS
    *-- Default file name
    constants: c_filename_default(40) type c
    value 'VOLSAP/MAXVRLIB/manu_retail_vendor',
    c_kalsk(2) type c value '05'.
    SELECTION SCREEN
    selection-screen begin of block b1 with frame.
    selection-screen: begin of block b2 with frame title text-001 .
    select-options:s$lifnr for lfa1-lifnr .
    parameters:p$relif as checkbox.
    selection-screen end of block b2.
    selection-screen: begin of block b3 with frame title text-002 .
    parameters: p$file(128) obligatory default c_filename_default.
    selection-screen end of block b3.
    selection-screen end of block b1 .
    START OF SELECTION
    start-of-selection.
    if not s$lifnr is initial.
    perform get_vendor_data .
    endif.
    perform build_file .
    perform display_file .
    END OF SELECTION
    end-of-selection .
    *& Form GET_VENDOR_DATA
    form get_vendor_data .
    select lifnr
    name1
    from lfa1
    into table i_lfa1
    where lifnr in s$lifnr .
    if not i_lfa1[] is initial.
    sort i_lfa1 by lifnr .
    select lifnr
    kalsk
    minbw
    from lfm1
    into table i_lfm1
    for all entries in i_lfa1
    where lifnr = i_lfa1-lifnr .
    select lifnr
    relif
    from eina
    into table i_eina
    for all entries in i_lfa1
    where lifnr = i_lfa1-lifnr
    and relif = 'X'.
    endif.
    endform. " GET_VENDOR_DATA
    *& Form BUILD_FILE
    form build_file .
    loop at i_lfa1 into ws_lfa1 .
    ws_final-lifnr = ws_lfa1-lifnr .
    ws_final-name1 = ws_lfa1-name1 .
    read table i_lfm1 into ws_lfm1 with key lifnr = ws_lfa1-lifnr .
    if ws_lfm1-kalsk = c_kalsk .
    ws_final-kalsk = 'X'.
    endif.
    ws_final-minbw = ws_lfm1-minbw .
    ws_final-eoln = 'X'.
    if p$relif = 'X'.
    CLEAR P_FLAG.
    LOOP AT I_EINA INTO WS_EINA
    WHERE LIFNR = WS_LFA1-LIFNR
    AND RELIF = 'X'.
    P_FLAG = 'X'.
    EXIT.
    ENDLOOP.
    IF P_FLAG = 'X'.
    APPEND WS_FINAL TO I_FINAL .
    CLEAR WS_FINAL.
    ENDIF
    read table i_eina into ws_eina with key lifnr = ws_lfa1-lifnr
    relif = 'X'.
    if sy-subrc = 0.
    append ws_final to i_final .
    clear ws_final.
    endif.
    else.
    append ws_final to i_final .
    clear ws_final.
    endif.
    endloop .
    endform. " BUILD_FILE
    *& Form DISPLAY_FILE
    form display_file .
    data: l_lines type i.
    describe table i_final lines l_lines.
    if l_lines > 0.
    perform open_file using p$file.
    loop at i_final into ws_final.
    transfer ws_final to p$file.
    endloop.
    close dataset p$file.
    else.
    write: / 'no data found'.
    endif.
    endform. " DISPLAY_FILE
    *& Form open_file
    Open an output file, customizing default name to include
    vendor number and job completion timestamp.
    form open_file using file_nm.
    data: l_vendor like eina-lifnr,
    l_timestamp(12) type c.
    Get correct path/filename for the system we're running on
    call function 'FILE_GET_NAME'
    exporting
    logical_filename = 'ZVOL'
    parameter_1 = file_nm
    importing
    file_name = file_nm.
    Open file for output
    open dataset file_nm for output in text mode encoding default.
    if sy-subrc ne 0.
    message e368(00) with 'Error opening output file:' file_nm.
    endif.
    endform. "open_file
    All definitions needed for the platform-independent assignment of file names are maintained client-independently with transaction FILE. Logical file names (but not logical file paths) can also be defined specifically for the current client with transaction SF01. Transaction SF07 generates a list of current definitions.
    Edited by: krupa jani on Aug 20, 2008 6:55 AM

  • Find the installation Path of the current running VM on Windows

    Hello,
    I have a java class started by webstart.
    In this class I would like to find the absolute path of the current running vm? This is important to me because I need to start an exe file (using ProcessBuilder) and hand it the path of the java VM,
    For example I could try something like this:
    private static File findJDK() throws Exception {
    String s = System.getProperty("java.home");
    File myJRE = new File(s);
    if (new File(myJRE, "bin/javac.exe").isFile()) {
    return myJRE;
    File parent = myJRE.getParentFile();
    if (new File(parent, "bin/javac.exe").isFile()) {
    return parent;
    for (String pathel : System.getenv("PATH").split(File.pathSeparator)) {
    File bindir = new File(pathel);
    if (new File(bindir, "javac.exe").isFile()) {
    return bindir.getParentFile();
    return myJRE;
    But I would like the above code to be more fool proof!
    For example the "java.home" could be wrongly set.
    Since java is allready running I would have hopped that I could query the Runtime. But there seems to be no method providing the running java VM path?
    I also tried looking at the jnlp services API but no luck.
    I would be also interested find the lastest java VM on the client Windows machine....
    Many greetings
    john

    http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties()
    bye
    TPD

Maybe you are looking for

  • Macbook Installation Problems

    Hello everyone thanks in advance to anyone who reads and responds to this. I've been having some ridiculous problems with my Macbook lately. Recently I tried installing Windows on my macbook through bootcamp, big mistake. It was laggy unresponsive, a

  • Error in Certificate creation

    i want to configure for an application with name myapp in tomcat for that purpose i am following procedure to create a certificate The following steps are followed for creation of SSL Certificate for tomcat version5.0 1. C:\Program Files\Java\jdk1.5.

  • HT1386 Why wont itune acknowledge that my ipod is plugged in!?

    I recently downloaded the latest update to itunes on my laptop and now it wont acknowledge that my ipod is plugged in and therefore it now wont sync. My laptop recognises it is plugged in as it comes up with an 'apple ipod' icon. Any one know how i c

  • BICS: BI Consumer Services

    Hey experts, I'm looking for information on SAP BI Consumer Services (BICS). The only thing I found is that BICS is a layer between BEx and BI. What is BICS? Why should I use/need it? Where can in find some info? Thanks Steven

  • Lost adobe jenson font

    I purchased InDesign CS3, CS2, CS1, and CS6 all from the Adobe Store. I had to reformat my HD and lost Adobe Jenson Pro, which was included with InDesign CS3. CS6 does not include it. I contacted Adobe Support to see if I could download Jenson Pro, s