Frage

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.

War es hilfreich?

Lösung 2

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

Andere Tipps

Try this:

String content = new URL("http://192.168.1.181/file.txt").getContent();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top