开发者

Reading file from localhost

开发者 https://www.devze.com 2023-03-01 05:59 出处:网络
I am开发者_运维知识库 trying to read a text file from my localhost (WAMP), but getting nothing back.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消