How to specify relative path for file name in java class

I have a directory structure like this.
C:\Aurora\com\optemys\aurora\validation
I have a class Test.java under the validation folder.
I have various files under the same folder i.e validation.
If I want to access the file "test.properties" in Test.java, how can I just specify "test.properties" & not "C:\Aurora\com\optemys\aurora\validation\test.properties".
I dont want to hardcode any file path into the class. How can I specify the relative file name into the class.
Thanks In Advance
Sachin

switch the name in Test.properties and use
this.getClass().getResourceAsStream(fileName)

Similar Messages

  • How to specify relative path for background image  in xsl

    Hi,
    I am generating a PDF from Apcahe FOP. I have an xsl for that, in the xsl fo:block I am displaying a background image. When the image path is absolute like..C:\image\logo.png it works fine. But I want to have the image in my WebContent\images folder and my xsl file is in WebContent\xsls folder. So when I try giving the relative path as ../images/logo.png, the image is not displayed.
    Can anyone tell how to do this???
    Thanks,
    Sanjeev.

    I have a fo:block like this :
    <fo:block border-style="solid" border-width="0.2pt" text-align="left"
                             background-image="url('http://localhost:8080/Project/images/table_header_center.png')"
                             font-size="8pt" font-weight="bold" color="white" padding-top="1pt"
                             padding-bottom="1pt">
                             <xsl:value-of select="tr/td/span" />
                        </fo:block>In the above code you can see that the the background-image="url('http://localhost:8080/Project/images/table_header_center.png')"
    has been given as absolute. The images folder is in my WebContent directory. I want this path to be relative to the context of my application , something like background-image="url('../images/table_header_center.png')".
    Thanks.
    sanjeev.

  • Relative path for files

    hi all,
    I am making a small program that needs to store some of the users preferences in a text file. I want the text file to be in the jar when i am finished and in the same folder as the main class. I am having a problem though with writing to a reading the file in a relative path. when i use "args.txt" it reads to the c:\args.txt and not the folder in which the program runs. Same thing with "\\args.txt" and "/args.txt". Any help? Thanks! :)

    If your file is in the same directory as the program the relative path is simply the file name : "args.txt". Also possible is "./args.txt".
    Keep in mind though that you can't write to a file in a jar, and even reading it is more complicated than with the ordinary I/O classes.
    Look up the getResourceAsStream method in the API (I think it's a method of the ClassLoader class).

  • Reading from a file. How to ask the user for file name at run time????

    I have the code to read from a file but my problem is how to prompt the user for the file name at run time.
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class FileRead {
        public static void main(String args[]) {
            Scanner scan = null;
            File file = new File("Results.txt");
            String number;
            try {
                scan = new Scanner(file);
                while (scan.hasNext()){
                number = scan.next();
                System.out.println(number);}
            catch (FileNotFoundException ex1){
                System.out.println("No such file");
            catch (IllegalStateException ex2){
                System.out.println("Did you close the read by mistake");
            catch (InputMismatchException ex){
                System.out.println("File structure incorrect");
            finally{
                scan.close();}
    }Any hints would be greatly appreciated. Thank you in advance

    I have read through some of the tutorials that you have directed me too and they are very useful, thank you. however there are still a few things that i am not clear about. I am using net beans 5.0 I have placed a text file named Results.txt into the project at the root so the program can view it.
    When I use the code that you provided me with, does it matter where the file is, or will it look through everywhere on the hard drive to find a match?
    This code compiles but at run time it comes up with this error
    run-single:
    java.lang.NoClassDefFoundError: NamedFile
    Exception in thread "main"
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    import java.util.Scanner;
    import java.io.*;
    class NamedFileInput
      public static void main (String[] args) throws IOException
        int num, square;   
        // this Scanner is used to read what the user enters
        Scanner user = new Scanner( System.in );
        String  fileName;
        System.out.print("File Name: ");
        fileName = user.nextLine().trim();
        File file = new File( fileName );     // create a File object
        // this Scanner is used to read from the file
        Scanner scan = new Scanner( file );     
        while( scan.hasNextInt() )   // is there more data to process?
          num = scan.nextInt();
          square = num * num ;     
          System.out.println("The square of " + num + " is " + square);
    }his is the code that i used. It is the same as the code you posted for me (on chapter 23 I/O using Scanner and PrintStream) Sorry im just really stuck on this!!

  • How to set default path for file open in SQL Developer

    Hi,
    I am new to Oracle SQL Developer. Everytime when I open a file, it will default to the install directory. It is hurtingmy hand because I have to click back to the folder where I put my sql statements.
    Is there any way to set the Home or Work button to point to the location I like? or add anther button to point to my folder? I just don't want to click 5 to 10 times to open a file.

    There are a few things. One is that you can set a working directory for any files you run in the SQL Worksheet i.e. @myfile.sql will pick up this directory.
    You can also set a preference for exporting files.
    Also if you use File -> Open, it should remember where you were the last time, so you hunt the first time, then it remembers for the next time. There is a bug for ctrl-O that always goes back to the original directory, but that has been fixed for the next patch release, so ctrl -O will also remember where you were last.
    The differences here are because we are dependent on the IDE from JDeveloper, and so we don't have full control over the Save and Open dialogs. We are aware of this frustration and are planning to change this for a future release.
    Regards
    Sue

  • Using relative path for in file/ftp adapter

    Hi All,
    How to have a relative path for file/ ftp adapter's inbound/outbound operation?
    Example: Consider $ORA_HOME = /home/oracle --> This environment variable can be different on different machines
    i want to drop a file in to $ORA_HOME/folder1/folder2 (Or poll for a file).
    <partnerLinkBinding name="FTP">
    <property name="wsdlLocation">FTP.wsdl</property>
    <property name="out_dir" type="LogicalDirectory">What do i write here???</property>
    <property name="retryInterval">60</property>
    </partnerLinkBinding>
    if i cant configure this in partner link section or in activation agent sction, how else do i achieve this?
    i am using 10.1.3.* version.
    Thanks in advance.
    Roshan.

    You can achive it using the deployment scripts if the directory is changing on the basis of the environment
    If you want to change at run time than you can use the jca properties to set using the variables at runtime.
    Regards,
    Ajay

  • Get the relative path for java class

    How to get Relative path for java class which is inside in web-inf directory in webapps

    ajay.manchu wrote:
    Hi gimbal2,
    My Requirement is i need to run a java class from batch file,when i created batch file in that i need to mention the complete path of the java class,so instead of mentioning that i want to provide only java class name,thats why i asked that one..
    can u help me regarding that....
    Thanks in advanceI wonder how that would work then. Let's take a fictive example. You have a class com.mycompany.myapp.Foo. This would mean that the class is stored in some directory like this:
    c:/webrootdir/myapp/WEB-INF/classes/com/mycompany/myapp/Foo.classTo be able to run such a class from the commandline using Java, you would have to invoke this command:
    java -cp c:/webrootdir/myapp/WEB-INF/classes com.mycompany.myapp.FooHow would knowing the exact path to this class help you?

  • How can I write relative path in File, ImageIcon objects

    I have downloaded examples from
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/index.html
    but for some reason images are invisible until I write absolute paths?(I use windows) How can I write relative path in File, ImageIcon objects?

    Hello;
    I've found a lot of complaints about this through the Forte forum as well as on Dejanews. I'm just curious as to whether any of you ended up finding a solution to this problem.
    There was one posting about setting up the subdirectory as a URL rather than a String and then using that as the source of the ImageIcon ... but this didn't work for me.
    Any help whatsoever would be appreciated.
    Thanks!

  • How do I change the .php file name for a page of my site?

    how do I change the .php file name for a page of my site? The only link to the page is the nav. button link for it in the global nav. The reason I need to change the file name is we want the breadcrumbing name to change and the breadcrumbing is linked to the file name.

    The reason I need to change the file name is we want the breadcrumbing name to change and the breadcrumbing is linked to the file name.
    I don't understand this reason. How would changing the file extension solve your breadcrumb issue? Why don't you explain the issue in more detail.

  • How to retrieve the path and the name of the destination file in a link annotation

    Hi,
    In C++:
    How to retrieve the path and the name of the destination file in a link annotation and a Launch action.
    Sample of my code:
    //Determine if the annotation is a Link annotation
    if (PDAnnotGetSubtype(annot) == ASAtomFromString("Link")) {
    //Determine if the action is a Launch action
    if (PDActionGetSubtype(action) == ASAtomFromString("Launch")) {
    // What is the method ?
    Regards
    David G

    In general, get the annotation as a Cos object and examine it, in
    accordance with the PDF Reference.
    Aandi Inston

  • Windows cannot access the specified device, path, or file.

    NOTE:  My access is through terminal services. 
    I received a new server to load my IBM Rational products.  I was able to load ClearQuest, Req Pro and ClearCase with no problems.  Because this machine is being used as a web interface for the products, I needed to also load Crystal Reports XI along with the embedded report server.  Well, I got everything installed but the embedded reports server. 
    On my attempt to double click on the file that would extract and install the addins needed I received the error message:
    Windows cannot access the specified device, path, or file.  You may not have the appropriate permissions to access the item.
    After some testing I see that if I select any executable associated with installing an application, I get this error.
    I've been searching all over the internet for a solution to this proble.  Does anyone know why this happens and what I can do to fix it?

    Ok this will be a long post, and for starters I wanted to point something out to everyone - there is two separate discussions going on in this thread. On one side you have a discussion about servers and people using thin clients or Citrix having this error
    code and changing Internet Explorer to resolve this conflict. Then on the other side all the stand alone home users with XP and Vista and 7 trying to figure out what is going on with their install that has the exact same error code. Microsoft in their infinite
    wisdom has given this error code to relate to multiple different errors hence the confusion.
    Now here is my story, with out a resolution yet.
    Ok, so I ran into a real nasty trojan virus, that is now resolved and gone. However, when I went into the process of being able to resolve this issue a sticky byproduct was this permissions issue. This is how it happens, I download a video with Firefox or
    any browser Opera, IE whatever. Then after I have downloaded it into the proper location I can see it within the downloads list from the browser, should I double click to launch the video with WMV it will fail with that error "Windows cannot access the
    specified device, path, or file. You may not have the appropriate permission to access the item". However, should I open the directory and then launch from the true download location, rather in the list of the files within the browser download list it
    will launch fine. This is the problem I can utilize the programs directly launching them from explorer, however should I try and launch a program from inside another program it will fail to launch.
    This is a Vista 64 bit installation, and I am pretty tech savvy individual. What I have tried thus far is to take owner ship of the directory since trusted installer was the owner previously. After I had done that I went into the permissions of the exe and
    sought to make sure that the file was open for everyone to be able to modify and have full control - it was. After that I also tried launching the browsers as admin privileges to see if it would still launch. It will not it refuses to allow calls to this directory.
    That being said it is also a big problem when I use Corel DVD Moviefactory, because this program is trying to launch other programs from this directory to run. So, I need to figure out why is it that I am not able to have programs make calls to this directory
    and try and launch exe files and fail, yet the permissions are fine and I can launch them from directly clicking on the item in a directory?
    Further clarification as to what happens:
    Firefox downloads to Harvester\downloads
    All my pictures, movies, executable, rar/zip, reside in this directory "downloads"
    In the browser Firefox there is a "downloads" [contrl+J] list that shows what you have downloaded through the browser
    All of these items are able to double click and execute from this list with out having to navigate to the "downloads" directory
    When executing a WMV file it will fail and error out with the "Windows cannot access the specified device, path, or file. You may not have the appropriate permission to access the item" error.
    However, navigating to this directory will allow me to launch all programs with out any problem, the difference is I am launching from the file rather than through a program making a call to the x86 directory to launch the file. If I have an item that doesn't
    require a program to launch from the x86 directory it will launch ok through Firefox, ex InfanView, HJsplit, etc.
    This is a problem with other programs making calls to external programs residing in the x86 directory like Corel Moviefactory 7. While running it will make the same error "Windows cannot access the specified device, path, or file. You may not have the
    appropriate permission to access the item" when trying to make a new DVD, because it utilizes something in that directory an external program.
    This happens with Opera as well, don't know about IE I don't use it.
    What I have done thus far:
    Removed my firewall that was MS native firewall
    Removed my anti-virus and malware software - AVG, MalwareBytes, Windows Defender, Windows Security Essentials, Spybot Search and Destroy, Spy cop, and a few others
    Went and took ownership of the directory
    Tried registry hacks
    Altered AVG to exclude the (x86) directory
    Re-installed AVG and MalwareBytes to see if I can repair the file
    Shared the (x86) directory for everyone and inherited the permissions
    Tried CLI restoring of default permissions
    Tried to make changes in safe mode still shut down.
    This is where I am now....waiting for a scan to end to reboot and check to see if I was able to make any progress.

  • "windows cannot access specified device, path or file", adobe reader x

    hi,
    i had an older version of reader (9.something i think) that started making troubles, so i removed it (via control panel) and tried to use reader x instead. but after installing it i tried to run it and got this message titled "c:\programfiles\adobe\reader10.0\eula.exe":
    "windows cannot access specified device, path or file. you may not have the appropriate permitions to access the item".
    after clicking "ok" the program shuts.
    i downloaded this version from adobe's site and registered. i also tried to go back to version 9 but the installation itself wouldn't go.
    i'm using windows xp and downloaded reader using chrome. i deleted all previous adobe reader files from my computer prior to downloading, so it should behave as if this the first time this program was installed on it.
    how can i solve it? (i've already tried going through the whole process again and again)
    thank you for any help.

    I have found out how to solve this issue..
    Took A few days to figure it out and a lot of installs and un-installing
    Install CS6 master collection again and restart your machine- Make sure all anti-virus is disabled
    What you have to do:
    1. Press Start
    2. go under "Abode Master Collection CS6 (it should say its empty)
    3. now left click the folder "Adobe Master Collection" and open it..
    4. it will now come up with all programmes that SHOULD have worked - their thumbnails will not be visible it will look as if its corrupted.
    5. Now this is a long procedure- go on the first shortcut, lefts click and go to properties.
    6. Then select the option that says "Open File Location" it will then take you to its main folder.
    7. Left click the highlighted Programme within the main folder, then go on properties
    8. Go on the security Tab, press "continue" then you go on "Add" then type your account name, then "check name" then tick the box "full control"
    9. Then navigate to the "compatibility" Tab and select "Run this programme as an administrator (if you don't do this it will come up with another error)
    You should now have the thumbnail (picture) for the programme now
    You have to now repeat this for the rest of the programmes/shortcut's within the "Adobe Master Collection" Folder

  • Relative Path for Jquery into Content Editor Web Part

    Hi;
    I'd add a Content Editor Web Part (CEWP) to a web part zone. I'd edit that CEWP in HTML view and add my script which load Jquery and my question :  how to use a relative
    path for Jquery :
    <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true"
      Localizable="false" />
    <script src="/sites/XXX/Style%20Library/Scripts/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    My code
    </script>
    Regards

    Hi;
    Firstly, I have used : 
    <script src="/Style%20Library/Scripts/jquery.min.js" type="text/javascript"></script>
    But any result and any change and If I add /Sites/XXX/ : it works correctly ?
    My code is :
    <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true"
        Localizable="false" />
    <script src="/sites/XXX/Style Library/Scripts/jquery.min.js" type="text/javascript"></script>    
    <script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(displayTitle, "SP.js");
    var site;
      var context;
      function displayTitle() {
        //Get the current client context
        context = SP.ClientContext.get_current();
        //Add the site to query queue
        site = context.get_web();
        context.load(site);
        //Run the query on the server
        context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    function onQueryFailed(sender, args) {
      alert('request failed ' + args.get_message() +
        '\n' + args.get_stackTrace());
    function onQuerySucceeded(sender, args) {
        $("#layoutsTable table th span").html("Bienvenue sur le site " + site.get_title() + " - Direction Technique");
        $("#zz17_V4QuickLaunchMenu ul.root li span:contains('Biblioth')").parent().parent().hide();
        $("#zz17_V4QuickLaunchMenu ul.root li span:contains('Listes')").parent().parent().hide();
    </script>

  • How to position the cursor in File Name area in JFileChooser??

    Hi,
    I have been trying to position the cursor directly to filename area in JFileChooser. But no success.
    It positions itself at the directory path by default.
    How should I achieve this?
    The problem is that I do not know the name of this
    component used for File Name area hence difficult to
    use "requestFocus() or getFocus()" like methods.
    Thanks for your help.
    -Manoj

    Somewhere I saw a tip that explained how to do it, but I didn't keep a link to it. But basically it's like this: JFileChooser is a Container, so getComponent(n) will return the n-th component in the JFileChooser. One of them is the one you want to give the focus to, and I expect it will be a JTextField. A little experimentation should tell you which index you need to use.

  • Need script to add path and file name to fillable  form

    I have a fillable pdf form that I would like to have a script that adds the path and file name to the form. This script would be in a field at the end of the document.
    I am a newbie to javascript and formcalc. The script will be the only one in the form.
    Thanks for any assistance.
    Lisa

    Hi,
    I have a sample that attach a file to the PDF and write in a text field the file name. I don´t know how to get the full path and it only works in Acrobat. To work in Adobe Reader is necessary the LC Reader Extensions to give some special permissions to the document. But, regard this, you still want the sample send me a email to [email protected]
    Best Regards,

Maybe you are looking for

  • Error while updating a page

    Hello champs, i have done Create page now i am doing an update page.. In the pageRequest() of the update page i am invoking a method update() in the same App. module...while doing so im facing an error " No method with signature - No method with sign

  • PI Scenarios using MM-SUS

    We have SRM 7 EHP1. Also, we have two systems ECC 6. One of them with EHP 4 and the other without EHP 4. We are setting the scenario for MM-SUS. I understand that the integration of MM-SUS using ECC with EHP4, we can use the PI scenario: SE_Services_

  • GP Task not appearing in UWL

    Hi, We have GP WD java application which is running CE 7.31 sp05. Some of the GP task is not appearing in UWL . What might be case,please suggest.

  • How to create a new DataBase using Oracle 10g Express Edition???

    Hello, I am new to Oracle, I am used to Microsoft SQL Server (Enterprise Manager). Here in Oracle I do not get how do I create a DataBase, and then create tables on it. could anyone please explain to me how to do it?

  • PHP MySQL 2 column list

    I am building at site in dreamweaver using PHP/MySQL. I have a page that will list a bunch of categories. I would like to have them in a two column list instead of one. It will look better as far as the design goes. How can I do this. I would like ea