import java.io.File;
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 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");
}
}
}
这种方式只是修改了原来文件的编码