Browse Source

增加繁体字批量转简体的java代码

liuyuqi 4 years ago
parent
commit
ae5974c9ec
5 changed files with 111 additions and 0 deletions
  1. 5 0
      .gitignore
  2. 16 0
      f2j/.classpath
  3. 23 0
      f2j/.project
  4. 34 0
      f2j/pom.xml
  5. 33 0
      f2j/src/me/yoqi/f2j/Main.java

+ 5 - 0
.gitignore

@@ -26,3 +26,8 @@ Gemfile.lock
 
 /package-lock.json
 npm-debug.log
+
+
+/f2j/.settings
+/f2j/target
+/f2j/bin

+ 16 - 0
f2j/.classpath

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 23 - 0
f2j/.project

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>f2j</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 34 - 0
f2j/pom.xml

@@ -0,0 +1,34 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>me.yoqi</groupId>
+	<artifactId>f2j</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>f2j</name>
+	<description>繁体字批量转简体字</description>
+	<build>
+		<sourceDirectory>src</sourceDirectory>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.6.1</version>
+				<configuration>
+					<source />
+					<target />
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>com.github.houbb</groupId>
+			<artifactId>opencc4j</artifactId>
+			<version>1.0.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>1.3.2</version>
+		</dependency>
+	</dependencies>
+</project>

+ 33 - 0
f2j/src/me/yoqi/f2j/Main.java

@@ -0,0 +1,33 @@
+package me.yoqi.f2j;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.commons.io.FileUtils;
+
+import com.github.houbb.opencc4j.util.ZhConverterUtil;
+
+/**
+ * 繁体字(Traditional Chinese)批量转换为简体字(Simplifiled Chinese)
+ * 
+ * @author liuyuqi
+ *
+ */
+public class Main {
+
+	@SuppressWarnings("unchecked")
+	public static void main(String[] args) throws IOException {
+		String srcDirPath = "/home/twtech/workspace/cordova-docs/www/docs/zh-cn";
+		String SimpleChineseDirPath = "/home/twtech/workspace/cordova-docs/www/docs/zh-cn-res";
+
+		// 获取所有md文件
+		Collection<File> subFile = FileUtils.listFiles(new File(srcDirPath), new String[] { "md" }, true);
+
+		for (File file : subFile) {
+			String SimpleChineseFilePath = SimpleChineseDirPath + file.getAbsolutePath().substring(srcDirPath.length());
+			FileUtils.writeStringToFile(new File(SimpleChineseFilePath),
+					ZhConverterUtil.convertToSimple(FileUtils.readFileToString(file)), "UTF-8");
+		}
+	}
+}