how to get url html contents to string in java

后端 未结 5 1868
北恋
北恋 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:03

    Resolved it using spring added the bean to the spring config file

      
        
      
    

    then read it in my method

            // read the file into a resource
            ClassPathResource fileResource =
                (ClassPathResource)context.getApplicationContext().getBean("receiptTemplate");
            BufferedReader br = new BufferedReader(new FileReader(fileResource.getFile()));
            String line;
            StringBuffer sb =
                new StringBuffer();
    
            // read contents line by line and store in the string
            while ((line =
                br.readLine()) != null) {
                sb.append(line);
            }
            br.close();
            return sb.toString();
    

提交回复
热议问题