Reading file from localhost
I am开发者_运维知识库 trying to read a text file from my localhost (WAMP), but getting nothing back. Could someone point out what I am doing wrong please. This is how I am trying to achieve it.
try {
URL url = new URL("http://10.0.2.2/text.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((str = in.readLine()) != null) {
tv.append(str);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) { }
It works with a true URL, but not whenever I use localhost. I have tried using localhost and 127.0.0.1 in URL too.
精彩评论