String str="";
try {
String s="";
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("test.htm"));
while((s=br.readLine())!=null)
str+=s;
}catch(Exception e){System.out.println(e.toString());System.exit(0);}
String str1=".*(<[\\s]*body[^>]*>)(.*)(<[\\s]*/[\\s]*body[\\s]*>).*";
str=str.replaceAll(str1,"$2");
System.out.println(str);
try {
String s="";
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("test.htm"));
while((s=br.readLine())!=null)
str+=s;
}catch(Exception e){System.out.println(e.toString());System.exit(0);}
String str1=".*(<[\\s]*body[^>]*>)(.*)(<[\\s]*/[\\s]*body[\\s]*>).*";
str=str.replaceAll(str1,"$2");
System.out.println(str);
<P> </P>
<br>
都要去掉?
那样的正则表达是应该怎么写呢?希望 beyond_xiruo(希偌) 有办法。不过楼主为什么不用JEditorPane呢?那个更好用一些吧
str=str.replaceAll(str1,"$2"); 中"$2"表示什么意思?另外,能讲解一下=".*(<[\\s]*body[^>]*>)(.*)(<[\\s]*/[\\s]*body[\\s]*>).*"吗?
正则表达式
.* 表示任何0个或者更多的任意字符
< 和 / 和 >都表示了他们原来的意思,代表一个字符
[\\s]*表示0个或者更多的空白字符(空白字符不仅仅表示空白键,包括\t等等)
body表示原来的意思,代表字符串
[^>]* 表示匹配0个或者更多个 不等于>字符 的字符。
$2表示第二个打圆括号的表达式里面的内容,在这里就是(.*)
详细的请看正则表达式的介绍吧。
String str=....;//你的网页所有内容.
int begin=str.indexOf("<body>");
int end=str.indexOf("</body>");//int end=str.lastIndexOf("</body>");
String bodystr=str.substring(begin,end);
String beginstr="<body>";
int begin=str.indexOf(beginstr)+beginstr.length();
我刚接触java,希望大家给点意见!
我的问题就像 XKP(低等下人) 所说的应该去掉<p> <br>等标识,说白了就是像在网页中显示的一样,另外,我还想接着问,加入我还想显示html文件中的
图片,音频等,应该怎么做呢?用什么控件呢?
我想就差不多了,试试看?
继续向各位学习!!!!!