Search code examples
fileweboracle-adfjdeveloper

Read from file in managed bean


I work in JDeveloper and created a Web Fusion Application. I have a managed bean and in one of it's methods I want to read data from my custom file (just like Scanner does it). How can I do it? Where should I place this file in my project?


Solution

  • You should create a folder within your Web Content. Then copy your file manually there (go to c:/Oracle/MiddleWare/Jdeveloper/Jdev/myWork/YourApp/ViewController...). Back in JDeveloper refresh your application and you should see the new file inside your new folder. Then you refer to it simply as "/MyFolder/myfile.txt" or anything else.

    Edited

    public ServletContext getContext() {
        return (ServletContext)getFacesContext().getExternalContext().getContext();
    }
    ServletContext context = getContext(); 
    InputStream fs = context.getResourceAsStream("/Folder/file");