批量改变HTML文件的meta信息中的编码方式
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-07-25 09:08:18
asal
1209 orang telah melayarinya
有的时候html文件的编码方式与meta信息中指定的编码方式不同,可以通过这段代码搞一下。 此程序依赖jsoup和commons-io包
- 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");
- }
- }
- }
复制代码
|
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Topik-topik yang berkaitan
Lagi>