NonameSL
NonameSL

Reputation: 1475

FileSystemNotFoundException: Provider "jndi" not installed

I have this JSP code that I'm trying to run to read all lines from a .java file. My directory tree looks like this:

| WebContent

- | resources

- - | Foobar.java (The file I need to read it's lines)

- jspfile.jsp (Where I'm running the code) 

My code:

String.join("\n", (String[])Files.readAllLines(Paths.get(getServletContext().getResource("/resources/Foobar.java").toURI()), Charset.defaultCharset()).toArray());

Whenever I try to run this I get this error:

java.nio.file.FileSystemNotFoundException: Provider "jndi" not installed
    java.nio.file.Paths.get(Unknown Source)

I honestly have no idea what that means and I'd love some help

Upvotes: 1

Views: 961

Answers (1)

NonameSL
NonameSL

Reputation: 1475

Thanks all, I wound up using this code:

public String readResource(String resource){
        try{
            BufferedReader in = new BufferedReader(new InputStreamReader(getServletContext().getResourceAsStream("/resources/"+resource)));
        String line = null;

        String data = "";
        while((line = in.readLine()) != null) {
            if(data!="")data+="\n";
            data+=line;
        }
        return data;
        }catch(IOException e){
            return "";
        }
    }

It works great!

Upvotes: 1

Related Questions