0

这是我的代码:我正在使用我的系统的 IP 地址,其中包含 listofitems.txt 文件:

    try {
         Create a URL for the desired page
String ipadd=ip.getText().toString();   
        URL url = new URL("http://192.168.1.2/listofitems.txt");


        // Read all the text returned by the server
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str = in.readLine();

        String[] items = new String[]{

        items = str.split(",");

    in.close();

    } catch (MalformedURLException e) {

    } catch (IOException e) {

    }

我有平板电脑连接到带有无线路由器(WLAN)的系统。请帮忙!!!谢谢你!!!

4

1 回答 1

0

试试这个:

try {
            // Create a URL for the desired page
            URL url = new URL("http://192.168.1.2/listofitems.txt");

            // Read all the text returned by the server
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String all=""; 
            String str;
            while ((str = in.readLine()) != null) {
                all+=str;
            }
            in.close();

            items = all.split(",");


        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }

并将其添加到清单中:

<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
于 2012-08-08T11:29:45.670 回答