문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

Try this:

String content = new URL("http://192.168.1.181/file.txt").getContent();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top