读取HTML文件,生成HTML字符串

思路:通过流读取,然后拼接

      这个也比较简单,学过流的同学应该都会,只不过长时间不用就都忘了,这个是封装好的,我们可以拿过来直接用,废话不多说,直接上代码;

代码:
  //filePathAndName : 你要转换的html的 绝对路径
   public static String readFile(String filePathAndName) {
        String fileContent = "";
        try {
            File f = new File(filePathAndName);
            if(f.isFile()&&f.exists()){
                InputStreamReader read = new InputStreamReader(new FileInputStream(f),"UTF-8");
                BufferedReader reader=new BufferedReader(read);
                String line;
                while ((line = reader.readLine()) != null) {
           //将读取到的字符拼接  
                  fileContent += line;
                }
                read.close();
            }
        } catch (Exception e) {
            System.out.println("读取文件内容操作出错");
            e.printStackTrace();
        }
        System.out.println("fileContent:"+fileContent);
        return fileContent;
    }

很多时候我们不需要把这些东西都记住,因为他会占用我们很多的精力和时间,我们只需要在袄子中有个印象,当有需求的时候我们做到能够知道使用什么去解决,至于怎么写我们没有必要去记住,因为我们可以百度....当然如果你能记住的话更好。。。
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值