比如
http://localhost:8080/KnowledgeBase/xml/test.xml
有个XML文件
我JAVA端 如何 读取

解决方案 »

  1.   

    URL getUrl = new URL("http://localhost:8080/KnowledgeBase/xml/test.xml"
    );
    HttpURLConnection
            HttpURLConnection connection = (HttpURLConnection) getUrl
                    .openConnection();
            // 进行连接,但是实际上get request要在下一句的connection.getInputStream()函数中才会真正发到
            // 服务器
            connection.connect();
            // 取得输入流,并使用Reader读取
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            String lines;
            while ((lines = reader.readLine()) != null) {
                System.out.println(lines);
            }
            reader.close();
            // 断开连接
            connection.disconnect();