Can't open files using relative paths

That seems straightforward but i can't figure out how I can have access to
image files stored in the same directory with the compiled classes.
Here's my what I want to do
windowsButton = new JButton("Windows", new ImageIcon("icon_cool.gif"));
but it doesn't work :(
however if i specify the absolute path to images everything works fine.
I tried also copying images into the source directory it didn't work.
I thought about a workaround like If i could get the absolute path of the
class that loads images that would be great but i have no clue how to get
that absolute path.
i code in netbeans so src and classes are separated.
Thanks in advance for your replies. If u feel like u need more details i'll
try to provide them :)

In addition to jverd's answer, here is a tutorial
dealing with images and icons
"How to Use Icons":
http://java.sun.com/docs/books/tutorial/uiswing/misc/i
con.html
It gices some examples of how to use the
getResource() method to load your images.As the tutorial points out, simple path is more general than using class loader and resources for it.
If OP's problem is on the line of this simplicity, he has to learn relevant details of a particular IDE or,
if he hates the kind of learning, he'd be better off throwing away and foget it forever.
It reminds me of a long-time belief that IDE is too big an /unnecessary/ obstacle for beginners.
Does anyone know, does Eclipse have similar awkwardness for resource path issue?

Similar Messages

  • Creation of file using relative path

    I am working on JSP
    I want to create a file object by passing a relative path as parameter to
    File f = new File("<relative path>");
    i encounter the following error
    "it says server cannot find the file in the path specified."
    I have searched the forums but not able to get any relevant expalination.
    Its an urgent requirement. So please reply. Thanks in advance.

    I notice that servletContext.getRealPath()
    returns path from root directory to the ../webapps/examples folder
    am i correct or it can get real path for any file residing in any subfolder
    like ../webapps/examples/a/df/a.txt ?

  • Sharepoint 2013 Does not open files using UNC path from Server

    Hi All,
    Just setup our new 2013 sharepoint intranet site , I tried adding a hyperlink to a document stored on our server using a UNC path file://servername/share/filename.doc but when i click on it it takes me to a blank Webpage in a new tab.
    I have turned on "open client applications" in the site collection features hoping that would help ....buuuuuut it did not.
    Also tried variations in the UNC path eg: \\servername\share\filename.doc etc..
    Any help would be greatly appreciated
    Thanks

    Open start run > type > file://servername/share/filename.doc Does this works
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/63b229de-ce4a-42be-b209-2c0f33d4b0d5/problem-opening-an-access-file-from-a-unc-file-link-in-sharepoint?forum=sharepointgeneralprevious
    Actually the problem I described is an Internet Explorer issue and I will try to get resolution in the appropriate forum.  IE exhibits the described behavior whether the link is in a Sharepoint site page, or in a regular non-Sharepoint web page. 
    Mozilla does not have the issue.
    Check below:
    http://social.msdn.microsoft.com/Forums/en-US/3f2c34cc-5686-4e03-ba26-092aaa29ff33/link-from-document-library-to-unc-path
    If this helped you resolve your issue, please mark it Answered

  • How can I open files using a default zoom level?

    When I open a file in acrobat reader, the letters are too small that I have to zoom out the documents in order to read them. Is it a way to pre-set the zoom level every time I open the files?

    I have the same issue - .
    We NEED a way to have OUR default zoom override whatever some author thought was a wonderful zoom level.
    The Zoom setting in Page Display and also in Accessibility are not honored in V10.1.7, and from other posts, not in earlier versions either.
    And, yes I can provide many documents which apparently have author created zoom levels to prove the point, if needed.

  • Can any one suggest me how can I use relative path inside SSIS pacakge to access config file ?

    Can any one suggest me how can I use relative path inside SSIS pacakge to access config file ? Please help me as its urgent.THanks for your help in advance.

    Hi Jay,
    SSIS can only recognize the absolute path of a XML Configuration file, the relative path is not supported. Furthermore, if the XML Configuration file is already generated, we can use the Environment variable package configuration type instead so that
    SSIS runtime automatically looks for the configuration file from the path defined in the environment variable. This is convenient when we need to deploy a package to different environment. We only need to define the environment variable for package configurations
    once on each server, and then the variable can be used by all the packages on this server.
    Regards,
    Mike Yin
    TechNet Community Support

  • Snow Leopard 10.6.2 CS4 InDesign can't open files with a "#" in file path

    Snow Leopard 10.6.2 CS4 InDesign can't open files with a "#" in file path using any of these perfectly normal methods:
    1. double-click file in the Finder (e.g in a Folder on your Mac or on your Mac desktop etc.)
    2. select file and choose "File... Open" command-o in the Finder
    3. drag file to the application icon in the Finder.
    4. Select file in Bridge and double-click, choose File.. Open.. or Drag icon to InDesign icon in dock.
    If you try to open an ID file named with a "#", you will get an error message "Missing required parameter 'from' for event 'open.'"
    This happens to any InDesign file that has a "#" (pound sign, number sign, or hash) in the filename or in the file path (any parent folder).
    To reproduce
    Name an InDesign file Test#.idd Try to open it in the Finder or Bridge (as opposed to the "Open" dilaog of InDeisng itself).
    "Solution"
    The file WILL open using File... Open... command-o while in InDesign application.
    Rename the file or folders that have a "#" (shift-3) in the filename.
    Report to Adobe if it bugs you.
    This does not occur in "plain" Leopard 10.5 nor Tiger 10.4
    Untested in Panther or before and
    Untested with CS3 and earlier in Snow Leaopard.
    Anyone have those and want to try this... ?

    In case this really bothers you: we've added a workaround for this into Soxy. If you enable the option, these documents will open fine on double-click.
    You need Soxy 1.0.7 from:
    http://www.rorohiko.com/soxy
    Go to the 'Soxy' - 'Preferences' - 'Other' dialog window, and enable 'Open InDesign via Script'
    (Irrelevant background info (it's all invisible to the user): the workaround works by special-casing how Soxy opens documents in InDesign: instead of using AppleScript, Soxy will use ExtendScript to instruct InDesign to open the document - which works fine).

  • How to read/know/use  relative paths in java files ?

    I am able to access files in java after using the
    String TxtURL = "file:///c:/files/TEXTS/";and then loop
    = new File(ma.TxtURL +filename );However , I need to use this in several drives , C , D E etc , how can I use relative path ?
    I used these but they didn't work
    String TxtURL = "file:///TEXTS/";
    String TxtURL = "file:////TEXTS/";
    String TxtURL = "file:///./TEXTS/";
    String TxtURL = "file:///../TEXTS/";

    ya batch , I want to run a java program from batch file
    java C:\...\fileand as u know that C will change , so any suggestions/solutions ?
    thanks

  • Can't use relative paths in jsp pages or javabeans

    Hi everyone,
    Can someone please help me with this little problem.
    When I want to use in a JSP page the object 'FileReadInput' to read in a file, it can't find when I only give the filename. The target file and source file are in the same directory so I would expect if I only give the filename, it will automatically search in the current directory. But when I give the complete absolute path, everything works fine. Is it possible to use relative paths in a jsp or javabean file?
    By the way, I am working with JDeveloper from Oracle. (maybe that has something to do with my problem)
    Can someone help me???
    Thx

    My dear friend,
    It will not work at all. coz, for any jsp file, ur application server will create a .java file and then .class file in a directory other than the directory where ur .jsp file present. that's why, ur file to be read can't be found. that's why use the following.
    String path=getServletConfig().getServletContext().getRealPath("/")+File.seperator+"yourfilename";

  • Error message: "Can't open file "[File path, file name].key"

    If I attempt to open any Keynote files, I now get this error message.
    "Can't open file "[File path: file name].key"
    To clarify, the text in the square brackets above would be the file path and then the file name.
    The file then will appear on the screen, but is unresponsive to any clicks or menu commands.
    The files will open successfully on other Macs, so they aren't corrupt.
    Also - I've just checked, and opening Keynote and trying to create a new presentation leads to the same problem: All screen menus / buttons are dead - all I can do is drag the window around the screen.
    I've tried to reinstall Keynote, but this hasn't resolved the problem.
    Is there some corrupt preference file (or similar) that I need to get rid of? Is there an easy way to do a complete uninstall of Keynote so I can try another install? Or is this a symptom of something else?
    All ideas gratefully appreciated!
    Message was edited by: Brendan Donlon

    All the issues I describe in my questions around this time re: Keynote were actually symptoms of a soon-to-die laptop. The Hard Disc was corrupting, and Keynote was the first application to be affected.

  • When I try to open iweb I get the following message: Can't open file "~/Sites/NAVIGATOR/index.html." How do I fix this? Using 10.6.3 soon to be 10.6.6 and then Lion.

    When I try to open iweb I get the following message: Can’t open file “~/Sites/NAVIGATOR/index.html.” How do I fix this? Using 10.6.3 soon to be 10.6.6 and then Lion. I have never opened the product before and have had it on the computer since new.

    Go into your Users/Home/Library/Application Support/iWeb folder and see if there's a file titled Domain.sites.  If there is double click on it and see if iWeb opens.
    If there is no Domain file there do the following:
    delete the iWeb preference files, com.apple.iWeb.plist and com.apple.iWeb.plist.lockfile, that resides in your Home() /Library/Preferences folder.
    go to your Home()/Library/Caches/com.apple.iWeb folder and delete its contents.
    Click to view full size
    launch iWeb and try again.
    OT

  • Hi, I got iMac and I can not open file "doc" when I have downloaded from distance learning internet page. I have office program, but when I try to open file it shows: u1-assesment.doc uses a file type that is  blocked from opening in this version.?

    Hi, I got iMac and I can not open file "doc" when I have downloaded from distance learning internet page. I have office program, but when I try to open file it shows: u1-assesment.doc uses a file type that is  blocked from opening in this version.?
    I have tryed to change just extension from doc to docx, but it doesn't work. I am new user, please help

    Consider the Mcrosoft Office:Mac forums as well:
    Office for Mac forums
    Here is an MS page that deals with that error message:
    http://answers.microsoft.com/en-us/mac/forum/macoffice2011-macword/bs0811doc-use s-a-file-type-that-is-blocked-from/548ce159-8157-419e-9552-1789594fafe9

  • Error: can't open file (-43)

    Hi Guys,
    I am a newbie to iphone development....I was trying my hand on audio recording module using apple SpeakHere demo....
    The problem is that I want to save the audio file in NSDocumentDirectory and want to playback the audio recorded from there...
    But if i am changing the path from NNSTemporaryDirectory to NSDocumentDirectory i got error stating "can't open file (-43)".
    I searched forum , but did not found any satisfactory answer...Can any body please tell me a way how to overcome this error.
    Waiting for your valuable suggestion.
    Thanks in advance
    Quest.

    It would be best to post a little example code showing where your problem is.

  • How can i upload file using ajax post request and jsp

    Hi
    this is my code files
    addPhoto.jsp
    <html>
    <head>
    <title>Add Photo</title>
    <script>
    var optionNo = 0;
    var i=1;
    var val=0;
    var file = 0;
    var exten = new Array(".jpg",".jpeg",".gif");
    function addValues()
         for(var i=0;i<5;i++)
              optionNo += 1;
              oNewOption = new Option();
              oNewOption.text = optionNo;
              oNewOption.value = optionNo;
              addSelect.add(oNewOption);
    function addBoxes()
         var str = "";
         var j=0;
         val = document.getElementById('addSelect').value;
         for(j=1; j<= val; j++)
              str = str + '<font size=3>file:' + j + '</font>';
              str = str + '<input type="file" id=filepath'+ j +' name=file'+ j + ' onchange="uploadFile(hidden'+ j + '.value)"><div id="result'+ j +'"></div>
              str = str + '<input type="hidden" name="hidden' + j + '" value=' + j +'>';
         document.getElementById('addPhoto').innerHTML = str;
    function uploadFile(value)
    var str = "filepath" + value;
    file = value;
    var param = document.getElementById(str).value;
    var parameter = "filepath=" + param;
    alert(parameter.length);
    if(checkValidity(param))
    var url = "uploadFile.jsp";
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    req.open("POST", url, true);
    req.setRequestHeader("Content-type", "multipart/form-data");
    //req.setRequestHeader("Content-length", parameter.length);
    req.setRequestHeader("Connection", "close");
    req.onreadystatechange = callback;
    req.send(null);
         else
              document.getElementById("result" + file).innerHTML = "upload .jpeg,.jpg,.gif Files Only";
    function callback() {
    if (req.readyState == 4) {
    updatepage(req.responseText);
    function updatepage(str){
         document.getElementById("result" + file).innerHTML = str;
    function checkValidity(str)
         var i=0;
         var j=0;
         var str1 = str.substring(str.lastIndexOf("."),str.length);
         alert(str1);
         for(i=0;i<exten.length;i++)
         if(str1.search(exten) != -1)
              j++;
              break;
         if(j>0)
              return true;
         else
              return false;
    </script>
    </head>
    <body onload="addValues()">
    <h5>Add Photo(s)</h5>
    <select id="addSelect" name="addSelect" onchange="addBoxes()">
    <option id="select" selected>Select</option>
    </select>
    <div id="addPhoto"></div>
    </body>
    </html>
    uploadFile.jsp
    <%@page import="java.io.*"%>
    <%
    /*try
    String contentType = request.getContentType();
         System.out.println(request.getMethod());
         System.out.println("Content type is :: " +contentType); 
         if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
              DataInputStream in = new DataInputStream(request.getInputStream());
              DataInputStream in1 = in;
              int formDataLength = request.getContentLength();
    System.out.println(formDataLength);
              byte dataBytes[] = new byte[formDataLength];
              int byteRead = 0;
              int totalBytesRead = 0;
              while (totalBytesRead < formDataLength)
                   byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);
                   totalBytesRead += byteRead;
              out.println("<br>totalBytesRead : " + totalBytesRead + " : formDataLength = " + formDataLength);
         } catch(Exception e) {
              e.printStackTrace();
         try
         String filePath = request.getParameter("filepath");
         System.out.println(filePath);
         File f= new File(filePath);
         String path = f.getName();
         String contentType = request.getContentType();
         System.out.println(contentType);
         //InputStream in = new FileInputStream(filePath);
         DataInputStream in = new DataInputStream(request.getInputStream());
         int formDataLength = request.getContentLength();
         System.out.println(formDataLength);
    byte[] buf = new byte[1024];
    OutputStream out1 = new FileOutputStream("c:/docs/" + path);
    int len;
    while ((len = in.read(buf)) > 0) {
    out1.write(buf, 0, len);
    in.close();
    out1.close();
         out.write("File Uploaded SucssesFully");
    catch(Exception e)
         e.printStackTrace();
         out.write("error while Writing File");
    %>
    the above code in request.getContentType() i am getting 0. I am not passing the content length. for the same application with out using Ajax i am
    getting the size of file... it is very very urgent for me.. pls help me out on this...
    Any one having the code on this pls mail me the code...
    my mail id ... [email protected]
    Regards
    Ashok Kumar

    Sure, you can upload a file, using a form input element of type file. You pick this up with a servlet, though you need a special request wrapper to sort out the multi-part request you get back that way (there's a suitable package on jakarta.apache.org/commons)
    The servlet decrypts the file and can pass the results to a JSP for display.
    Don't try to do the complicated stuff in a JSP, it all gets incredibly messy, and that's not what JSPs are for.

  • Using Relative Path instead of Full Path OMBPlus

    Can we use relative paths in OMBPlus scripts instead of full paths. For example all my OMBplus (tcl) scripts are in folder;
    C:\tfsroot2\Interfaces and Extracts\branches\Interfaces and Extracts1.1\000 - OWB Prototype\deploy\ora.stg
    and the MDX file I would like to deploy is in
    C:\tfsroot2\Interfaces and Extracts\branches\Interfaces and Extracts1.1\000 - OWB Prototype\deploy\ora.stg\scripts\dwextract\tables
    but when I try to use
    OMBIMPORT MDL_FILE '../scripts/dwextract/tables/$tblName.mdx'
    instead of
    OMBIMPORT MDL_FILE 'C:/tfsroot2/Interfaces and Extracts/branches/Interfaces and Extracts1.1/000 - OWB Prototype/deploy/ora.stg/scripts/dwextract/tables/$tblName.mdx'
    It does not work.
    I use
    call "C:\OraHome_1\owb\bin\win32\OMBPlus.bat" "C:\tfsroot2\Interfaces and Extracts\branches\Interfaces and Extracts1.1\000 - OWB Prototype\deploy\ora.stg\OMB_DEPLOY_TBL.tcl" XTRCT_WRK_INPUT_FILE
    in order to execute.
    I think it is because It set the OMBPlus.bat location is a base folder. Any way to overcome this issue and use relative paths instead of the full path?

    OK, a couple of things. First, you need to remember that TCL treats back-slashes as an escape character. Always use forward slashes in your paths, or double up the back slashes .
    So, this should work:
    CD "C:\tfsroot2\Interfaces and Extracts\branches\Interfaces and Extracts1.1\000 - OWB Prototype\deploy\ora.stg"
    call OMBPlus.bat "C:\\tfsroot2\\Interfaces and Extracts\\branches\\Interfaces and Extracts1.1\\000 - OWB Prototype\\deploy\\ora.stg\\OMB_DEPLOY_TBL.tcl" XTRCT_WRK_INPUT_FILEor this:
    CD "C\tfsroot2\Interfaces and Extracts\branches\Interfaces and Extracts1.1\000 - OWB Prototype\deploy\ora.stg"
    call OMBPlus.bat "C:/tfsroot2/Interfaces and Extracts/branches/Interfaces and Extracts1.1/000 - OWB Prototype/deploy/ora.stg/OMB_DEPLOY_TBL.tcl" XTRCT_WRK_INPUT_FILEAs an FYI for OMB, if you are prone to doing a lot of scripts and so building libraries of common functions, you can also easilly use the "file" command in order to determine the current directory at runtime so you can plunk your script anywhere with it's required libraries and it will be able to source them at runtime.
    For example, all our scripts have this basic bit of code at the beginning so we can pass them between developers and it doesn't matter where anyone put their script directory - the scripts will find the libraries as long as they are co-located:
    #  Get Current Directory and time
    set dtstmp     [ clock format [clock seconds] -format {%Y%m%d_%H%M}]
    set scrpt      [ file split [file root [info script]]]
    set scriptDir  [ file dirname [info script]]
    set scriptName [ lindex $scrpt [expr [llength $scrpt]-1]]
    set cnfg_lib "$scriptDir/ombplus_config.tcl"
    set owb_lib  "$scriptDir/omb_library.tcl"
    set sql_lib  "$scriptDir/omb_sql_library.tcl"
    #  Import Lbraries
    #      Assumes that owb_config, omb_library, and omb_sql_library are in the same directory as this
    #      script.
    #get config file
    if [catch { set retstr [ source $cnfg_lib ] } errmsg] {
       puts "**********************************************************************"
       puts "* Libraries are missing from the current directory. Exiting.... *"
       puts "**********************************************************************"
       return -code 2
    #get standard library
    source $owb_lib
    source $sql_lib
    #  Set Logfile
    #    This will overwrite anything set in the config file.
    set LOG_PATH "$scriptDir/logs"
    file mkdir $LOG_PATH
    set    SPOOLFILE  ""
    append SPOOLFILE $LOG_PATH "/log_"  $scriptName "_" $tabName "_" $dtstmp ".txt"
    # Now the main script body goes from here.Cheers,
    Mike
    Edited by: zeppo on Aug 4, 2009 7:02 AM
    Edited by: zeppo on Aug 4, 2009 7:03 AM

  • Illustrator CC 2014 can't open files sent from Draw.

    Illustrator CC 2014 v18.0.0 (just installed today, 11/6/2014): I can't open files sent from Adobe Draw. The files send from Draw OK, but in Illustrator—which finally opens as advertised—I get an error message, i.e. The file "Dog - Drawing 1.draw" is in an unknown format and cannot be opened. This goes for all of my work, whether created in Ideas then opened recently in Draw, or files created in Draw from scratch.

    Illustrator files (.ai or .pdf)  that I save using CC 2014 vs 8.1.0 on my Windows (8.1) machine on our network server. I try to open them on Mac.
    'The File "x.pdf" is an unknown format and cannot be opened'
    This may in some way be related to accessing the file over the server since when I transfer the file to my lcal drive I don't get the same error.  I still can't open the file but I get an error near the end of the opening process :
    "Could not read the file because the plug-in made an invalid request of the Photoshop adaptor"
    Again, I can open this file using CC 2014 vs 8.1.0 on my Windows (8.1) machine.

Maybe you are looking for

  • LDAP users and Delivers

    Hi, I am using OBI 11.1.1.6.0 and i am using LDAP authentication through initialization block. Now when i want to create Agent i can't see users from ldap (i think those who are not currently logged). I also noticed that when i have configured SA Sys

  • Skylanders battleground I can not access. Please help me

    Anyone can help me

  • Any sailors out there?

    My wife and I are taking our sailboat into the South Pacific and need some advice on which Mac Pro we should upgrade to, and our needs are extremely specific. First and foremost, I want to integrate it with our ship's systems - as in HAM radio email,

  • Delivering Plant - Search strategy

    Can anyone advise if this delivering plant search strategy is exclusive i.e. it will stop upon first hit? Customer material info -> Ship to -> Material Thanks Peter

  • Study guide for OCA Java SE 7 Programmer I, exam 1Z1-803

    Are there any study guides available for this exam? Is it ok to use a book that is based on Java SE 6? Something like this parhaps: http://www.amazon.com/Certified-Associate-Study-CX-310-019-Certification/dp/0071490035/ref=sr_1_1?ie=UTF8&qid=13197356