how to get url html contents to string in java

后端 未结 5 1881
北恋
北恋 2021-02-04 17:49

I have a html file stored on the server. I have the URL path something like this:

I want to rea

5条回答
  •  故里飘歌
    2021-02-04 18:00

    For exemple :

            URL url = new URL("https://localhost:9443/genesis/Receipt/Receipt.html");
            URLConnection con = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String l;
            while ((l=in.readLine())!=null) {
                System.out.println(l);
            }
    

    You could use the inputstream in other ways, not just printing it.

    Of course if you have the path to the local file, you can also do

      InputStream in = new FileInputStream(new File(yourPath));
    

提交回复
热议问题