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

Similar Messages

  • How to get the current executing file/itself absolute directory?

    hellooo,
              gentlemen/lady, how to get the current executing file/itself absolute directory?
              thanks
              

              Hello,
              you can get the real path information of the JSP through the servlet context:
              http://java.sun.com/products/servlet/2.2/javadoc/index.html
              javax.servlet
              Interface ServletContext
              Method getRealPath
              Christian Plenagl
              Developer Relations Engineer
              BEA Support
              [email protected] (alex mok) wrote:
              >hellooo,
              >
              >gentlemen/lady, how to get the current executing file/itself absolute
              >directory?
              >
              >thanks
              

  • File path of a currently executing teststand test step

    How do i extract the file path for the currently executing LabVIEW test step within my operator interface.
    Many Thanks,
    Dave.

    Hi,
    I assume you need the SequenceFile Path where the LabView test step is located in TestStand.
    To reach to the currently executing step SequenceFile path you have to:
    1. get the SequenceContext for the execution
    2. get the currently executing step from the SequenceContext (SequenceContext.Step)
    3. get the sequence in which the step resides from the Step (Step.Sequence)
    4. get the containing sequence file for the Sequence (Sequence.SequenceFile)
    5. get the Path from the SequenceFile (SequenceFile.Path property)
    In case you want to determine the VI file path for the LabView test step Module one approach is:
    1. get the SequenceContext for the execution
    2. get the currently executing step from the SequenceContext (SequenceContext.Step)
    3. get the PropertyObject for the step (Step.AsPropertyObject)
    4. get the VI relative path from the step subproperty using "TS.SData.ViCall.VIPath" lookup string (PropObject.GetValString)
    5. now use the Engine.FindFile on the retrieved path at the step 4. above, to get the path to the executing VI
    Hope this helps,
    Silvius
    Silvius Iancu

  • Get the current absolute path name?

    How to get the current absolute path and file name in javascript?

    If using CS3 or CS4
    alert($.fileName);
    or this should work on all versions.
    function WhoAmI() {
    var where;
    try {var F = FO;
    }catch( err ) {where = File(err.fileName);}
    return where;
    NB: Neither will work if you are using binary scripts!

  • How to get the current filename and & or path

    How can I get the current path or filename?
    I didn't really find any answers in the net. this.path or app.path were suggested but I couldn't get it to work.
    Thanks in advance for your answer!
    Livecycle Designer ES 8.2.1.3144.1.471865

    Hi,
    event.target.path.toString();  will give the full path including the filename.
    event.target.documentFileName.toString();  will give the filename only.
    Good luck,
    Niall

  • How to get the current path of my application in java ?

    how to get the current path of my application in java ?
    thanks

    To get the path where your application has been installed you have to do the following:
    have a class called "what_ever" in the folder.
    then you do a litte:
    String path=
    what_ever.class.getRessource("what_ever.class").toString()
    That get you a string like:
    file:/C:/Program Files/Cool_program/what_ever.class
    Then you process the result a little to remove anything you don't want:
    path=path.substring(path.indexOf('/')+1),path.lastIndexOf('/'))
    //Might be a little error here but you should find out //quickly if it's the case
    And here you go, you have a nice
    C:/Program Files/Cool_program
    which is the path to your application.
    Hooray

  • How to get the current FILE PATH?

    I want to get the File Path on my Java Programming, which class / method can get a File Path on the windows?
    thanks!

    I want to get the current working directory(e.g.
    c:\Tomcat5.0\webapps\)
    If this is a web application you're talking about and you want the directory where that application is installed, that's almost certainly not the CWD. It might be one of the context or whatever variables that's available to servlets. Look in the servlet API and see what's there.

  • Can you get the file name of the current executing TSQL script?

    Can you get the file name of the current executing TSQL script? I wrote entries to a generic log file and would like to include the script name.

    Okay, So What you can do is
    1. Read get the version from your  database and redirect it to a text file(SQLCMD outout can be directed to text file using -o option or windows redirection operator >)
    2. Now you can read this value from the text file either inside a batch file or a powershell script and decide what operations you can do. 
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Getting the current path from which the form is runnig in 9i OAS

    Hi,
    We are using the built in Get_Application_property to get the
    current path in which the form is running. However this does not
    work in 9ioas and it only returns the form name and not the full
    path. Does anyone have any solutions to this problem?
    Thanks in Advance
    Jeet

    Place it in the classpath, then you can use ClassLoader#getResource().

  • How to get the "current date" in the BEx?

    Hi all,
    I need to get the "current date" in my Bex report in order to make a comparison. I know there is a "How to" which shows how to get the current date via a User Exit, but I didn't find it. Could you please help me?
    Thanks

    1. Create a  New Formula in Key Figures structure
    2. Give tech name and description and Select "New variable" option
    3. Next screen will launch Variable Wizard -> create a new variable with replacement path as processing type
    4. in next screene  select the date characteristic that represents the first date to use in the calculation (From Date)
    5. In the next  screen select Key in the Replace Variable with field. Leave all the other options as they are
    6. In the next Currencies and Units screen select Date as the Dimension ID.
    6. Save variable
    repeate the Above steps to create another variable (To Date)
    and now you can use these two new replacement path variables in your new formula.
    Dev

  • How to get the current tree element (node/childnode/childnode/...) ?

    Hello!
    I'm trying to create a kind of a navigation tree for my application.
    It should represent some elements of an XML structure and some other nodes for other options.
    The binding with the context is not a problem, I can create the tree up to all the levels I want to.
    The problem now is, that I don't know, how to get the "current tree element", when there is any action.
    For example:
    public void onActionSelect(...) {
    String test = wdContext.currentTreeNodeElement().getText();
    wdThis.wdGetContext().currentContextElement().setSelectedElement(test);
    With this method I can get the text of the "first level nodes". If I want to get the "second level node", I can do
    String test = wdContext.currentTreeNodeElement().currentChildElement.getText();
    ..and for the next levels so on.
    Isn't there any general method to get the information of the selected element without knowing before, whether it is a nodeElement or a nodeElement.currentChildElement or a nodeElement.currentChildElement.currentChildElement, ...?
    Greetings,
    Ramó

    Hi,
    if you following that pdf ,
    i think your not implemented the below code in DomodifyView method
    if (firstTime) {
          IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("TheNode");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "selectedElement".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onAction event. Parameter "selectedElement" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onAction. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnAction().addSourceMapping("path", "selectedElement");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "element".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onLoadChildren event. Parameter "element" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onLoadChildren. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnLoadChildren().addSourceMapping("path", "element");
    please cross check once.
    Thanks,
    Ramesh

  • JTree: How to get the currently selected node

    How do I get the currently selected node in JTree?
    getLastSelectedPathComponent() this method always return the last selected node and not the current one.
    Thanks in advance
    Sachin

    Use
    TreePath selectedPath = tree.getSelectionPath()If your tree allows multiple selections, use
    TreePath [] selectedPaths = tree.getSelectionPaths() this will return an array of all selected tree paths.
    Once you get the tree path, call the treePath.getLastPathComponent(). this should tell you the currently selected node.
    Hope this helps
    Sai Pullabhotla

  • I need to get the current assignee for a given request using SOA's java api

    I'm developing a spring app that interfaces with Oracle SOA suite and executes the actions such as approving requests using the api. I need to get the current assignee for each SOA Task this is dispalyed in the OIM console so it is getting it from somewhere. I tried getApprovers in the ITaskService api but this returns an empty list

    I have checked it once again and there indeed are links for ALUI components for Solaris on SPARC at edelivery.oracle.com. (Officially ALUI supports Solaris on SPARC only)
    If you have looked at Solaris x86, then you must not have found them. Please make sure that you are selecting the righ platform. Also, make sure that you click on the Aqualogic media pack so as to get the lists of the components included in it. (Point to Note: You need to go to the next level)
    For whichever component you are not able to find, try looking for it in the Metalink (My Oracle Support) if you have a support contract.

  • Trap the currently executing line number?

    Hi,
    how can one get the number of the currently executing line of code?
    Like what is generated when there are compilation/runtime errors.
    I saw LineNumberReader() & getLineNumber() but they seem to be for reading files or a jpanel (I think).
    thanks,
    HSC

    ok, with all your help I managed to get this:
                //----------------- stack trace for debugging ------------------           
                StackTraceElement[] e = new Throwable().getStackTrace();
                StackTraceElement stack[] = e;
                // stack[0] contains the method that created the exception.
                // stack[stack.length-1] contains the oldest method call.
                // Enumerate each stack element.
                //for (int i=0; i<stack.length; i++)
                int i=0;
                String filename = stack.getFileName();
    if (filename == null) {
    // The source filename is not available
    String className = stack[i].getClassName();
    String methodName = stack[i].getMethodName();
    boolean isNativeMethod = stack[i].isNativeMethod();
    int line = stack[i].getLineNumber();
    System.out.println(
    " >>className =" + className +
    " >> methodName =" + methodName +
    " >> line = " +line
    // } //end-for
    //----------------- stop stack trace for debugging ------------------
    Still don't quite understand it all but considering I've been learning java on my own for about 3 weeks I figure I'm doing better than a lot of newbies. - I am frustrated as hell, but I don't give up!
    thanks.
    Note: anyone looking for code examples you can look at: "The Java Developers Almanac 1.4" http://javaalmanac.com/

  • EXIT_SAPLEBNF_005 (ZXM06U51) - getting the current purchase order details

    I have a requirement to determine release agent in part based on who owns the budget. That's easy. The hard part is getting the current data (at least so far)...
    I have tried using the MEPO_DOC_* function moduless. They didn't even give me the amount (at least not in all situations).
    I have now tried using the class based interface (IF_PURCHASE_ORDER_MM) - which seems OK at first but has an unwanted side effect: it interferes heavily with the purchase order transaction.
    Currently I am struggling to get rid of the side effects, but there must be an easier way than the path I have started on. I've been looking for some sort of manager class which could be used to retrieve the interface reference without having to initialize it myself via CL_PO_HEADER_HANDLE_MM but haven't found one yet.
    Part of my problem is that the user exit is called twice, so if I buffer the handle transaction ME22N doesn't initialize correctly (initially appears in display mode becuase the first call for some reason is stating that it's transaction ME23N in change mode). If I don't buffer the handle, the switch to change mode doesn't work properly in ME23N. Thank you SAP!
    I've been struggling with this for more than a day now, so it's time to ask the experts to see if anyone can help me get out of this [Catch 22|http://en.wikipedia.org/wiki/Catch-22_%28logic%29|Catch 22 explanation in Wikipedia]-like situation
    FORM po_get_interface_handle
         USING value(pe_purchase_order) TYPE ekko-ebeln
         CHANGING po_purchase_order TYPE REF TO if_purchase_order_mm.
    * 2011-04-19 EX_KKILHAVN (Kjetil Kilhavn, Blue Consulting)
    * Buffer handles to avoid problems with multiple initializations
      TYPES: BEGIN OF buffer_po_handle,
               ebeln     TYPE ekko-ebeln,
               po_handle TYPE REF TO cl_po_header_handle_mm,
             END OF buffer_po_handle.
      STATICS: lt_po_handles_buffer TYPE SORTED TABLE OF buffer_po_handle
                                      WITH UNIQUE KEY ebeln.
      DATA: ls_po_handle         LIKE LINE OF lt_po_handles_buffer[],
            le_transaction_type  TYPE t160-trtyp,
            le_activity_category TYPE char01,
            le_transaction_code  TYPE syst-tcode,
            ls_document          TYPE mepo_document,
            le_result            TYPE mmpur_bool.
      READ TABLE lt_po_handles_buffer[]
           WITH TABLE KEY ebeln = pe_purchase_order
           INTO ls_po_handle.
      IF sy-subrc <> 0.
        ls_po_handle-ebeln = pe_purchase_order.
        CREATE OBJECT ls_po_handle-po_handle
          EXPORTING
            im_po_number = pe_purchase_order
          EXCEPTIONS
            failure      = 1.
        IF sy-subrc               =  0           AND
           ls_po_handle-po_handle IS NOT INITIAL.
          "Check transaction type must handle code being invoked from change transactions
          "and from other transactions (e.g. Business Workflow agent determination)
          CALL METHOD ls_po_handle-po_handle->get_transaction_state
            IMPORTING
              ex_trtyp = le_transaction_type
              ex_aktyp = le_activity_category
              ex_tcode = le_transaction_code.
          IF le_transaction_type IS INITIAL.
            le_transaction_type = 'A'.
          ENDIF.
          IF le_transaction_code IS INITIAL.
            le_transaction_code = 'ME23N'.
          ENDIF.
          ls_po_handle-po_handle->set_state( im_state = cl_po_header_handle_mm=>c_available ).
          MOVE: mmpur_po_process    TO ls_document-process,
               le_transaction_type  TO ls_document-trtyp,
               pe_purchase_order    TO ls_document-doc_key(10),
               mmpur_initiator_call TO ls_document-initiator-initiator.
          ls_po_handle-po_handle->po_initialize( im_document = ls_document ).
          CALL METHOD ls_po_handle-po_handle->po_read
            EXPORTING
              im_tcode     = le_transaction_code
              im_trtyp     = ls_document-trtyp
              im_aktyp     = le_activity_category "ls_document-trtyp
              im_po_number = pe_purchase_order
              im_document  = ls_document
            IMPORTING
              ex_result    = le_result.
          IF le_result = mmpur_yes.
            READ TABLE lt_po_handles_buffer[]
                 WITH TABLE KEY ebeln = ls_po_handle-ebeln
                 TRANSPORTING NO FIELDS.
            INSERT ls_po_handle INTO lt_po_handles_buffer[] INDEX sy-tabix.
          ENDIF.
        ENDIF.
      ENDIF.
      TRY.
          po_purchase_order = ls_po_handle-po_handle.
        CATCH cx_sy_move_cast_error.
      ENDTRY.
    ENDFORM.                    "po_get_interface_handle

    Hi ravi,
    can you please tell me the Tcode  for creation of purchaze order in SRM.
    thank you
    sunny.

Maybe you are looking for

  • I'm new user and I don't know...

    ... how to copy some of the BlackBerry device Messages (SMS and MMS) into my PC for archiving reasons, how I was used to do with my previous Nokia phone "PC Suite" desktop software. Many thanks for your help.

  • Trigger mail to vendor's company correspondence email for debit memos

    Hi We are issuing output for debit memos through MR90 for external send (nacha = 5) An email is sent to the vendor's email id maintained in the first page of XK02. However the email needs to be sent to the company correspondence email id (LFB1-INTAD)

  • Report server, error code 186

    I installed 9ias(http server, forms &report server , oem server) on windows 2000, but the report server don't startup, error code 186. can you tell me how to resolve the problem.

  • SWFs containing 3d movie clips do not display correctly

    I'm having difficulty using a swf with a 3d movie clip, it's displaying much larger in captivate than it does in any other context.  Are there known issues with 3d clips in captivate?

  • Publishing for a particular CMS

    Hi There Just new to using Muse but before I dive in and learn all its bells and whistles I want to make sure this software will export / publish to what I can use. I work for a company that use their own CMS platform for all our websites. We have a