2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Invoking an URL using FileReader in java

I found some piece of code to invoke and read the URL like,

BufferedReader in = new BufferedReader(new FileReader("https://localhost/kodetalk.js"));

But when I ran the above I am facing the below issue,

exception=https:/localhost/kodetalk.js (The filename, directory name, or volume label syntax is incorrect)

Generally FileReader is used to read the filesystem, not URLs.In your case "new FileReader("https://localhost/kodetalk.js")" reading the URL just like passing the path.

I hope the below snippet will solve your problem,

new InputStreamReader(new URL("https://localhost/kodetalk.js").openStream(), "UTF-8")

Answer is