How to specify a file path in java code to run on Unix machine?

Hi
I have a problem when running my project Swing on Unix machine.
In my code, the user will press a button and then the program will look for the file "ReadMe" in the folder "Documentation" , and reads the content of this file. My code is "Documentation\\ReadMe" and it works well on PC. (The folder "Documentation" is in the same directory with my Java code).
But when I try on Unix, the program can not read the file. It can only read the file "ReadMe" if I take this file and put it in the same directory with my Java code ( this means not through another folder). So how can we make it read the file in a folder ? It seems that "Documentation\\ReadMe" does not work in Unix, or the symbol "\\" does not work.
I would be thankful if anybody can help me with this.
Thank you very much

You really shouldn't use any path method, as neither are very consistant or platform independent. The JVM provides a way to grab resources from the classpath. These resources can be any data at all, in fact, it's how java itself locates classes. Here's an example how you would do this in a non-static method.
public URL getReadMe() {
  // In this context the forward slash is universal
  String docDirectory = "Documentation/"
  // We have to use the classloader to grab the resource
  ClassLoader cl = this.getClass().getClassLoader();
  // Next we get the resource 
  URL readMeURL = cl.getResource(docDirectory + "ReadMe");
  return readMeURL;
}The URL can be used in whatever way you need to get the information out of the resource. If it was an image you might use the "Toolkit" to make an image object out of it. The great thing about this method is it will work even if your loading the program out of a Jar file. The resource paths start at the top of the classpath, just like classes.

Similar Messages

  • How to use .properties files in Webdynpro Java code?

    Hi all,
      I want to use a logon.properties file when I initial a JCO connection pool in my webdynpro DC (JCO.addClientPool()),but  I found when I deployed this DC to the server, it always giv e me an FileNotFoundException. So I donot know how to deploy a .properties file to the server and how to access this file in my Java code?
    Thans and Best regards
    Deyang

    Hi,
    1) put .properties file to your packege under src\packages folder (src\packages\com\sdn\properties\jco.properties)
    2) load property:
         final InputStream is = getClass().getClassLoader().getResourceAsStream("com/sdn/properties/jco.properties");
         final Properties properties = new Properties();
         try
              properties.load(is);
         catch(Exception e)
              wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
    Regatds Maxim R.

  • How to specify term file when using static html to run webforms 10g

    I'm using static HTML to run forms
    document.writeln('<PARAM NAME="serverArgs" ');
    document.writeln(' VALUE="escapeParams=true module=genoa.fmx userid= sso_userid=%20 sso_formsid= sso_subDN= sso_usrDN= debug=no host= port= term=/forms90/hsd65html/genoa.res"> ');
    I'm specifying the term as term=/forms90/hsd65html/genoa.res.
    During forms startup I get the message unable to read the file. I can bwoense the file by http://server/forms90/hsd65html/genoa.res
    Any idea how to specify the term file in static html.
    Thanks

    term is not a http address, but a directory address. So, you have to specify the path on the server:
    term=c:\oracle\forms90\.....

  • How to specify the file path while doing bdc recording

    hi guys,
    using recording we specify transaction code where we enter all the details for the screen after that we get the recording program .....i have a doubt where can we specify the path for uploading a program from a local pc.......if possible can anyone provide a simple program to explain recording to upload an excel file from the system using recording

    Hi Gokul,
      You can use the following code to upload excel data into internal table.
       PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.
        CALL FUNCTION 'WS_UPLOAD'
          EXPORTING
               CODEPAGE                = ' '
               FILENAME                = P_FILE
               FILETYPE                = 'DAT'
               HEADLEN                 = ' '
               LINE_EXIT               = ' '
               TRUNCLEN                = ' '
               USER_FORM               = ' '
               USER_PROG               = ' '
          IMPORTING
               FILELENGTH              =
           TABLES
                DATA_TAB                = IT_FILE
          EXCEPTIONS
               CONVERSION_ERROR        = 1
               FILE_OPEN_ERROR         = 2
               FILE_READ_ERROR         = 3
               INVALID_TABLE_WIDTH     = 4
               INVALID_TYPE            = 5
               NO_BATCH                = 6
               UNKNOWN_ERROR           = 7
               GUI_REFUSE_FILETRANSFER = 8
               CUSTOMER_ERROR          = 9
               OTHERS                  = 10
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ELSE.
        CLEAR IT_FILE.
      ENDIF.
    In SAP Enterprise edition, You can use FM : GUI_UPLOAD.
    From internal table, Data will be moved to BDCDATA and continue with BDC coding.
    Reward, if useful.
    Thanks,
    USR

  • How to Save a File form a JAVA code into the CDrive

    Hello, i need to create a file and save it in the Cdrive of my computer.
    I could create the file and get the command prompt to ask me the file name to save it.
    However, my problem is that the file is saved in the Cdrive with nothing inside! I can manage to save the file and give it a name, but i can't save the inside of it... the page comes blank...
    if someone could help me and tell me why the inside isn't there and how to fix it, it could be very very helpfull!
    thx
    waiting for any reply
    the part where i know i got it wrong is this:
    // Save the File.txt in the Cdrive + MSG
                   System.out.println( FILENAME_MSG ) ;
                   BufferedReader br = new BufferedReader( new InputStreamReader ( System.in ),1 ) ;
                   PeastBase = br.readLine() ;
                   FileOutputStream fout = new FileOutputStream ( PeastBase ) ;
                   OutputStreamWriter out = new OutputStreamWriter ( fout , "Shift_JIS" ) ;
                   // Write in File
                   out.write( CopyBase ) ;
                   // Save PeastBase
                   out.flush() ;
                   // Close the Bufferedwriter
                   out.close() ;
    Anyway these are the complete code in case of need:
    import java.io.*;
    import java.util.ArrayList;
    class Exp11 {
         public static void main(String[] args) throws IOException{
              try{
                   File objCopyBaseFile = new File( "aaa" ) ;
                   File objPeastBaseFile = new File( "bbb" ) ;
                   //MAX Letters and Lines Input
                   final int MAX_COLS = 10 ;
                   final int MAX_ROWS = 10 ;
                   final String START_MSG = "Input any LETTER" ;
                   final String START_MSG1 = "10 LETTERS per Line, 10 LINES Max is Possible" ;
                   final String START_MSG2 = "Input w will Save the FILE and FINISH" ;
                   final String COUNT_STRING_ERROR = "Letters Input per Line is OVER" ;
                   final String COUNT_ROW_ERROR = "Lines Number is OVER" ;
                   final String FILENAME_MSG = "Input the File Name" ;
                   String PeastBase ;
                   String InputBase ;
                   String cpBuffer ;
                   String CopyBase ;
                   int rownumber ;
                   PeastBase = " " ;
                   InputBase = "w" ;
                   cpBuffer = " " ;
                   CopyBase = " " ;
                   rownumber = 0 ;
                   FileOutputStream fos = new FileOutputStream( "fos.txt" ) ;
                   OutputStreamWriter ow = new OutputStreamWriter( fos , "EUC-JP" ) ;
                   BufferedWriter bw = new BufferedWriter( new FileWriter ( "out.txt", true )) ;
                   // Start MSG
                   System.out.println( START_MSG ) ;
                   System.out.println( START_MSG1 ) ;
                   System.out.println( START_MSG2 ) ;
                   // Input
                   ArrayList<String> array = new ArrayList<String>() ;
                   int i ;
                   i = 0 ;
                   do {
                        BufferedReader br = new BufferedReader( new InputStreamReader ( System.in ),1 ) ;
                        PeastBase = br.readLine() ;
                        // Let's Count
                        if( !PeastBase.equals( InputBase) ){
                             rownumber ++ ;
                             // Check the Input letters
                             if ( countString(PeastBase,MAX_COLS )){
                                  array.add(PeastBase) ;
                             else{
                                  System.out.println( COUNT_STRING_ERROR ) ;
                             // Check the Lines
                             if ( countRow( rownumber,MAX_ROWS )){
                                  array.add( PeastBase ) ;
                             else{
                                  System.out.println( COUNT_ROW_ERROR ) ;
                   } while ( !PeastBase.equals( InputBase ) ) ;
                   // enter the data
                   for( int      j=0;j<array.size();j++ ){
                        System.out.println( "How Many Time Input==>"+array.get(j) ) ;
                   // Save the File.txt in the Cdrive + MSG
                   System.out.println( FILENAME_MSG ) ;
                   BufferedReader br = new BufferedReader( new InputStreamReader ( System.in ),1 ) ;
                   PeastBase = br.readLine() ;
                   FileOutputStream fout = new FileOutputStream ( PeastBase ) ;
                   OutputStreamWriter out = new OutputStreamWriter ( fout , "Shift_JIS" ) ;
                   // Write in File
                   out.write( CopyBase ) ;
                   // Save PeastBase
                   out.flush() ;
                   // Close the Bufferedwriter
                   out.close() ;
              catch ( IOException e ){
                   System.out.println( e ) ;
              finally{
         static boolean countString ( String bufString , int maxCount ) throws IOException{
              int StringCnt ;
              StringCnt = 0 ;
              // Count Letters per Lines
              StringCnt = bufString.length() ;
              if( maxCount>= StringCnt ){
                   return true ;
              else{
                   return false ;
         static boolean countRow ( int rownumber , int maxLine) throws IOException{
              int StringLine ;
              StringLine = 0 ;
              if( maxLine>= rownumber ){
                   return true ;
              else{
                   return false ;
    PLEASE ANY HELP
    THX

    I'm not great with IO yet, but I see you use
    out.write(CopyBase);But I only see you initialize CopyBase to equal an empty String.
    So it should be writing nothing to the file.

  • How to get the file path in adf application

    hii all,
    i have a txt file that i am using in my adf application,
    i am passing this txt file through a File Reader, for which i have to mention the file path.
    The file is in web-content and when i am hard coding the complete file path i.e C:/JDeveloper/myApp/ViewController/public_html/log.txt
    the application is working fine when run on integrated weblogic server.
    My requirement is to access this file without giving the static file path, as in case i have to use this application on any other machine..
    for that how to mention the file path-
    i tried using FacesContext to get the context path :-
    FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
    which gives me
    \myApp-ViewController-context-root
    after appending public_html\log.txt
    I am using the following path to access the file :-
    \myApp-ViewController-context-root\public_html\log.txt
    again i am getting the java.io.FileNotFoundException
    Does anyone know how to use file from inside the web-content without giving the complete path..???
    Thanks

    Hi,
    If you put your file under public_html folder, you can use this code to access the file:
    For example file is : log.txt
    FacesContext.getCurrentInstance().getExternalContext().getRealPath('/log.txt').toString().trim();
    Thanks.
    - LSR

  • How to give the file path in adf application

    Hii all,
    I want to use castor xml framework in adf application..
    for which i have to un- marshaller the xml file..
    by using following method-
    Person person = (Person)
    Unmarshaller.unmarshal(Person.class,
    new FileReader("src/com/person.xml"));
    if i use this method in a java class inside a main method directly it works fine,
    but when i try to initiate the java class through a jspx page deployed on integrated server..
    it gives the file not found exception..
    how to define the file path so it can be properly used even when application is deployed on server.
    Thanks

    duplicate {thread:id=2418158} ?
    I guess the path you are using is wrong. It works on your mashiene as the src path is available. When you run the app on a server (jspx file) there is no src path as long as you don't include it in your WAR wich you should not do anyway.
    If you need to access such data you can create a folder in your webroot folder and the the resources from there as /xml_folder_name or if the xml files shouldn't be visible from the outside put the folder under hte web-inf folder.
    Timo
    Edited by: Timo Hahn on 23.07.2012 16:20

  • Specify Report File Path by Expression

    TS201x Help under "Specifying Report File Paths by Expression" talks about  using a number of various macros, but starts the page showing how to also use FileGlobals. When specifying the expression (... >>Specify Report File Path by Expression>>Expression Browser), I'd like to combine macros with FileGlobals, but none of the FileGlobals are listed i.e. available. The expression builder has access to the StationGlobals though, but not to the FileGlobals.
    Is there a workaround, or at least an explanation, for this behaviour?
    Cheers
    Solved!
    Go to Solution.
    Attachments:
    Specifying Report File Paths by Expression.pdf ‏247 KB

    Thank for your quick reply!
    So, I created the expression in the >>Specify Report File Path by Expression>>Expression Browser, using FileGlobals.MyReportName as per your suggestion.
    Here, as expected, I got the first two error messages shown in the attached pdf.
    I also made sure that my sequence has the FileGlobals.MyReportName defined.
    When I run my sequence, I get the third error message shown in the attached pdf. I'd say this error message is also expected, since the non-listed FileGlobal
    referred to in my expression created above, never reaches NI_ReportGenerator.seq i.e. modelsupport2.dll. Or perhaps I completely missed a point in your message?
    In any case, please reply if you get a chance.
    Cheers
    Attachments:
    Specifying Report File Paths by Expression - Error Messages.pdf ‏113 KB

  • How to Install .CAP file in the Java Card?

    Hi Friends..
    How to install *.CAP* file in the Java Card?..
    I've GPShell script as follows :
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 2
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f
    install_for_load -pkgAID a00000006203010c01 -nvCodeLimit 500  -sdAID A000000003000000
    load -file HelloWorld.cap
    card_disconnect
    release_contextwith that script i can load HelloWorld.cap file successfully..
    Now, how to install the HelloWorld.cap file?..
    if i add script : load -file HelloWorld.cap i got this error :
    install -file HelloWorld.cap
    file name HelloWorld.cap
    Command --> 80E602001B09A00000006203010C0107A00000015100000006EF04C60201A80000
    Wrapped command --> 84E602002309A00000006203010C0107A00000015100000006EF04C60201
    A80030C859793049B85300
    Response <-- 6985
    install_for_load() returns 0x80206985 (6985: Command not allowed - Conditions of
    use not satisfied.)i ask this question because when i tried to select the applet through its AID, by this script :
    establish_context
    card_connect -readerNumber 2
    select -AID a00000006203010c0101i got this message error : select_application() returns 0x80216A82 (6A82: The application to be selected could not be found.)
    but there's exactly any that AID in my Java Card..
    here's is the list of AID from My Java Card :
    C:\GPShell-1.4.2>GPShell listgp211.txt
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 3
    * reader name OMNIKEY CardMan 5x21-CL 0
    select -AID a000000003000000
    Command --> 00A4040008A000000003000000
    Wrapped command --> 00A4040008A000000003000000
    Response <-- 6F108408A000000003000000A5049F6501FF9000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4
    f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    Command --> 80CA006600
    Wrapped command --> 80CA006600
    Response <-- 664C734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864
    886FC6B03640B06092A864886FC6B040215650B06092B8510864864020102660C060A2B060104012
    A026E01029000
    Command --> 8050000008AAF7A87C6013BC0300
    Wrapped command --> 8050000008AAF7A87C6013BC0300
    Response <-- 0000715457173C2A8FC1FF0200937A55C288805D8F2A04CCD43FA7E69000
    Command --> 848201001023CA18742D36165ED992CFF2146C3D51
    Wrapped command --> 848201001023CA18742D36165ED992CFF2146C3D51
    Response <-- 9000
    get_status -element 10
    Command --> 80F21000024F0000
    Wrapped command --> 84F210000A4F004FF8BE1492F7275400
    Response <-- 0CF0544C00004D4F44554C415201000009A00000006203010C010100010AA000000
    06203010C01019000
    GP211_get_status() returned 2 items
    List of Ex. Load File (AID state Ex. Module AIDs)
    f0544c00004d4f44554c4152        1
    a00000006203010c01      1
            a00000006203010c0101
    card_disconnect
    release_contextPlease help me..
    And please correct me if i'm wrong,,
    Thanks in advance..

    Any suggestions for my question?..
    Please help me..
    Thanks in advance..

  • File browse : How to keep the file path in the file browse field?

    Hello,
    I have
    1) file browse field called P2_FILE_PATH.
    2) a select list with submit : P2_REGION
    If i upload some file d:\abc.gif , then select some region in the P2_REGION,
    P2_FILE_PATH will become empty. But in the session, i can find the blob value. but not the "d:\abc.gif "
    Using the following script I could capture the value of P2_FILE_PATH in a field
    P2_TEST.
    onload="javascript:document.getElementById(P2_FILE_PATH').value = document.getElementById('P2_TEST').value;"
    P2_TEST contains d:\abc.gif .
    How to retain the file path, though some other field is selected and submitted?
    Thanks in advance.
    Regards,
    Archana

    Hello Archana,
    You can't do what you want because of some HTML security restrictions – nothing to do with APEX. As you found out, You can capture the value of this item. You can't set it. After submitting the page, the browser is the one to clear the item.
    The only workaround is to work with AJAX and not submit the page until the end of the user input phase.
    Regards,
    Arie.

  • How to use XSJS file path in Controller.js file

    Hi Experts,
    Regarding How to use XSJS file path in Controller.js file.
    I have gone through the SAP HANA Extended Application Services (Thomas Jung http://scn.sap.com/community/developer-center/hana/blog/2012/11/29/sap-hana-extended-application-services article.)
    Seems to be there is no information about the same. May be the article is targetted for Beginners and above. As I am a learner I am not able to do the same.
    var aUrl = '../../logic/demo_main.xsjs? (highlighted)
    Suppose my XSJS file is at http://ipaddress:8000/newtest/Func.XSJS.
    Can I use like below
    var aUrl = 'http://ipaddress:8000/newtest/Func.xsjs?
    or
    var aUrl = '../../newtest/Func.xsjs?
    I tried with multiple options but not able to get the expected output.
    Can you please provide more details on this?

    Dear Thomas,
    I am a abap developer , recently we meet a problem on our webdynpro report performnace issue. As in the development, we use SALV_WD_TABLE to design a ALV. and verything work correctly in our DEV system.
    But after when our QAS system, there are more records for the ALV, one of them has 21000 records. And in the layout, we have a column as checkbox.
    If we click any one checkbox, then the layout will respond almost 1~2 minutes. With debug I found the most time cost in the standard program.
    And with search I found that you have solution to solve it as 1,000,000 rows.
    So is it possible to provide some idea or solution to us?
    Many thanks for your help!
    BR
    Vincent Chen

  • How to set default file path while downloading alv output

    Hi,
    Can anyone tell me that how to set default file path while downloading the ALV output to system using Local file button on tool bar.
    Please look below screenshots:
    Kindly help me resolve it.
    Thanks in advance.
    Regards,
    Ashutosh Katara

    This information initial value is (maybe) stored in Windows Register (register.exe) at Software\SAP\SAPGUI Front\SAP Frontend Server\Filetransfer -> PathDownload, you can read it thru class CL_GUI_FRONTEND_SERVICES method GET_UPLOAD_DOWNLOAD_PATH and update it thru method REGISTRY_SET_VALUE. (Else there may be some parameter ID to force data, but I'm no longer sure)
    Regards,
    Raymond

  • How to set the file path dynamically based on sytem, username, and date

    Hi All,
    My requirement is upload the data into one  structure like xyz that is related to t.code MCSZ.
    file will be in  UNIx SERVER .
    PATH IS: /sapif
    file name is xy789 load .txt
    I have  to write code in one user-exit
    how can i set the file path for this.
    shall i put hard code file path?
    because i have to writecode in user-exit.
    plz tell me how to set the file path based ons syetem, username, date
    Thanks in advance
    Ram.A

    Concatenate the field SY-SYSID, SY-UNAME and SY-DATUM for the file path

  • How to give dynamic file path in the selection  screen

    Hi All,
    How to give dynamic file path f4 functionality to user on the selection so that he can browse for the path in the presentation serve? I believe there is one fun module is there for this purpose I am not getting that
    Please help me in this regard.
    Thanks&Regards
    Mahesh

    HI,
    check this program.
    <b>report ZWA_TEST2.
    PARAMETERS: a(100) default 'PRESS F4'.
    data: filet type table of FILE_TABLE.
    data: wa type file_table.
    data: count type i.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR a.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      CHANGING
        FILE_TABLE              = filet
        RC                      = count .
    loop at filet into wa.
      a = wa-FILENAME.
    endloop.</b>
    Regards,
    HRA

  • How to validate the file path when downloading.

    Hi
    How to validate the file path when downloading to Presentation or application Server.

    hiii
    you can validate file path by following way
    REPORT zvalidate.
    TYPE-POOLS: abap.
    DATA: w_direc TYPE string.
    DATA: w_bool TYPE abap_bool.
    w_dir = 'c:\Myfolder\'.
    CALL METHOD cl_gui_frontend_services=>directory_exist
    EXPORTING
    directory = w_direc
    RECEIVING
    result = w_bool
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    wrong_parameter = 3
    not_supported_by_gui = 4
    OTHERS = 5.
    IF NOT w_bool IS INITIAL.
    WRITE:/ 'Directory exists.'.
    ELSE.
    WRITE:/ 'Directory does not exist.'.
    ENDIF.
    regards
    twinkal

Maybe you are looking for

  • Setting a Radio Button value using Javascript

    After much research, I've figured out that the appropriate command to get the value of a Radio Button in APEX JavaScript is "html_RadioValue", but I haven't been able to figure out a command that will let you set the value of the Radio Button. Is the

  • Can't get stuff I paid for and downloaded to new computer with itunes.

    Ok, I was having some major issues. I posted them here: http://discussions.apple.com/thread.jspa?threadID=2569987 So I decided to download Itunes to my laptop and start over. I tryed to start my desktop to deautherize thta computer but I found out it

  • Google cookies cannot be blocked in Safari?

    When using OS 10.5 or higher and Safari, google cookies cannot be deleted. Google cookies show up when privacy setting is set to block cookies. Google cookies reappear minutes later after they are deleted and privacy set to block cookies. Google cook

  • Hi.. midlet in Japplet

    hi, i would appreciate if someone could give me some suggestion.. Exception in thread "AWT-EventQueue-7" java.lang.NoClassDefFoundError: javax/microedition/midlet/MIDlet      at java.lang.ClassLoader.defineClass1(Native Method)      at java.lang.Clas

  • Busco a "Marden Menezes" Tech Ed del a�o 2005

    El otro d�a estaba navegando en Internet y encontr� mi gemelo id�ntico que al parecer se llama "Marden Menezes" Lo encontr� en un archivo ppt al parecer de alg�n seminario Tech Ed del a�o 2005. En la pagina 3 se encuentra la persona id�ntica a mi que