批量改变HTML文件的meta信息中的编码方式
- 2016-12-08 11:55:00
- admin 原创
- 2276
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File input = new File("C:\\Users\\jack\\Desktop\\新建文件夹\\jdk-zh");
Iterator<File> it = FileUtils.iterateFiles(input, null, true);
while (it.hasNext()) {
File file = it.next();
Document doc = Jsoup.parse(file, "gb2312");
Elements content = doc.getElementsByAttributeValueStarting("content", "text/html;");
for (Element meta : content) {
meta.attr("content", "text/html; charset=utf-8");
System.out
.println("修改content--------" + file.getName() + "---");
}
FileUtils.writeStringToFile(file, doc.html(),"utf-8");
}
}
}
这种方式只是修改了原来文件的编码
发表评论
文章分类
联系方式
联系人: | 郑州-小万 |
---|---|
电话: | 13803993919 |
Email: | 1027060531@qq.com |
QQ: | 1027060531 |
网址: | www.wanhejia.com |
Update Required
To play the media you will need to either update your browser to a recent version or update your Flash plugin.