javaoracle-adfjdeveloperbacking-beans

How to read a file from a relative path in Jdeveloper ADF?


I want to read a file from a relative path in my Jdeveloper Adf project, I have my files in a path like this "\ProjectName\ViewController\public_html\files", my file is an image, so what can I do?, I want to my code to work in any server.


Solution

  • I hope my answer will be useful for others,

    I have read the file using code like the following,

            ServletContext servletCtx = ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
    
    
            InputStream inputStream = servletCtx.getResourceAsStream("/images/image.png");
    

    The path for my project and resurces is something like this

    "\ProjectName\ViewController\public_html\images"

    Regards.