It was because my file had no extension, so I add .txt, like in my exemple and it worked
Opening a file on a local server
-
09-07-2023 - |
Domanda
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.
Soluzione 2
Altri suggerimenti
Try this:
String content = new URL("http://192.168.1.181/file.txt").getContent();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow