<?xml version="1.0" encoding="gb18030" ?>
 <td>
      hello   world   
</td>  如上文本,我想用正则表达式(或其他方法)把     <?xml version="1.0" encoding="gb18030" ?>"去掉,只留下   "hello   world"   ,搞了一个下午都没搞好.   
    
  java.util.regex.Pattern;   
  java.util.regex.Matcher;   
    
  查了这两个类的javaDoc,可就是没搞店~~~~~~~~~   
    
  请各位给点提示,当然有例子最好了~~~~~~~~~谢谢!!!

解决方案 »

  1.   

    public class  Test
    {
    public static void main(String[] args) throws Exception
    {
    java.util.regex.Pattern p=java.util.regex.Pattern.compile("<[^>]*>");
    java.io.File file = new java.io.File("d://index.html");
    java.io.FileReader reader=new java.io.FileReader("d:\\index.html");
    java.io.BufferedReader in=new java.io.BufferedReader(reader);
    String s;
    StringBuffer sb=new StringBuffer();
    while((s=in.readLine())!=null)
    sb.append(s.replaceAll("<[^>]*>",""));
    System.out.println(sb.toString());
    }
    }
    index.html:<?xml version="1.0" encoding="gb18030" ?>
    <td>
    hello world
    </td>
      

  2.   

    谢谢imA(男的不会,会的不男) 啊...
    搞的我多迷糊了.我表达错了..
    1.<?xml version="1.0" encoding="gb18030" ?>
    <td>
          hello   world   
    </td>   
    不是一个文件,不是从文件里读,是一个字符串.2.我要显示<td>hello world</td>,刚刚搞错了.太糊涂了.不好意思了.