Question

I'm trying to open a file located on a local server.

        String stringIds = "";
        URL url = new URL("http://192.168.1.181/file.txt");
        URLConnection conn = url.openConnection();

        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line = "";
        while ((line = br.readLine()) != null)
        {
            stringIds += line;
        }

But the line:

BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

doesn't work (the conn.getInputStream() fails). I can open the file in Chrome.

Was it helpful?

Solution 2

It was because my file had no extension, so I add .txt, like in my exemple and it worked

OTHER TIPS

Try this:

String content = new URL("http://192.168.1.181/file.txt").getContent();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top