码迷,mamicode.com
首页 > 其他好文 > 详细

截取文件

时间:2017-07-12 21:28:59      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:try   todo   except   void   搜索   private   block   put   not   

private static void 吴绮莉() throws IOException, UnsupportedEncodingException {
        try {
            FileInputStream fs=new FileInputStream("F:\\吴绮莉.html");//创建对像,关联文件
            File f = new File("F:\\吴绮莉.html");
            int chang =(int)f.length();                 //获取文件长度
            byte [] b= new byte [chang];
            int an = fs.read(b);                        //读文件
        
            String str1 = new String(b,"UTF-8");        //转换编码
        
             int i=str1.indexOf("吴绮莉:");
             int j=str1.indexOf("_新浪网");
             String av = str1.substring(i, j);
        
            System.out.println(av);
            int s=str1.indexOf("<p>  新浪");              //第一次出现的指定元素在此列表中的索引,从 index 开始向前搜索
            int s1=str1.indexOf("<p>  成龙");            //从此结束
            String str2  = str1.substring(s, s1);       //声明截取的文件段落
      
            fs.close();                                  //关闭输入流
           String z=str2.replaceAll("<p>", " ");        //替换<p>标签
           String z2=z.replaceAll("</p>"," ");
          System.out.println(z2);                     // 输出截取文件
          fs.close();                                 // 关闭输入流   
        
        
        
          } catch (FileNotFoundException e) {
             // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

截取文件

标签:try   todo   except   void   搜索   private   block   put   not   

原文地址:http://www.cnblogs.com/ypc120336/p/7157250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!