Browse Source

java 版本添加pom文件

liuyuqi-dellpc 5 years ago
parent
commit
e98fda6e39
3 changed files with 43 additions and 15 deletions
  1. 7 1
      README.md
  2. 26 0
      java/pom.xml
  3. 10 14
      java/src/gbk2utf8/Convert.java

+ 7 - 1
README.md

@@ -8,7 +8,13 @@
 1. 配置项目文件夹
 python:pip install  os, chardet, codecs
 
-2. java执行 convert.java;php执行php convert.php; python执行python convert.py即可。
+2. 执行
+
+java执行 java —jar gbk2utf8.jar,或者 eclipse/idea 右键run即可;
+
+php执行 php convert.php; 
+
+python执行 python convert.py即可。
 
 ## 进度
 2017-12-17 python部分完成,对项目所有非utf-8编码的java文件全部转为utf-8编码。

+ 26 - 0
java/pom.xml

@@ -0,0 +1,26 @@
+<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>gbk2utf</groupId>
+  <artifactId>gbk2utf</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <build>
+    <sourceDirectory>src</sourceDirectory>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.5.1</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+	 <dependency>
+	    <groupId>org.apache.commons</groupId>
+	    <artifactId>commons-io</artifactId>
+	    <version>1.3.2</version>
+	</dependency>
+  </dependencies>
+</project>

+ 10 - 14
java/convert.java → java/src/gbk2utf8/Convert.java

@@ -1,22 +1,18 @@
-package cwj.bbb;
+package gbk2utf8;
 
-import java.io.*;
+import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
-
 import org.apache.commons.io.FileUtils;
-/*
- * 批量把文本文档的GBK编码转化为UTF-8
- * 使用用commons-io.jar实现文件的读取和写入
- * */
 
-public class EncodeTest1 {
+public class Convert {
 	public static void main(String[] args) throws IOException {
-		String srcDirPath = "/home/cwjy1202/hadoop/旅游领域/旅游类测试文档/地方文化";
+		String srcDirPath = "/home/xx/hadoop/xxproj";
 		// 转为UTF-8编码格式源码路径。这个路径可以若不存在,会自动建立。
-		String utf8DirPath = "/home/cwjy1202/hadoop/旅游领域/旅游类测试文档/地方文化1";
+		String utf8DirPath = "/home/xx/hadoop/1";
 
-		// 获取所有txt文件
-		Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[] { "txt" }, true);
+		// 获取所有txt,xml,java文件
+		Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[] { "txt","xml","java"}, true);
 
 		for (File javaGbkFile : javaGbkFileCol) {
 			// UTF8格式文件路径
@@ -24,6 +20,6 @@ public class EncodeTest1 {
 			// 使用GBK读取数据,然后用UTF-8写入数据
 			FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));
 		}
-
+		System.out.println("finish");
 	}
-}
+}