Skip to content

Commit 52402d7

Browse files
committed
修改在eclipse工具打开文件内容乱码问题
1 parent e5d85f5 commit 52402d7

File tree

1 file changed

+8
-6
lines changed
  • api-boot-project/api-boot-maven-plugins/api-boot-mybatis-enhance-maven-codegen/src/main/java/org/minbox/framework/api/boot/maven/plugin/mybatis/enhance/codegen/writer

1 file changed

+8
-6
lines changed

api-boot-project/api-boot-maven-plugins/api-boot-mybatis-enhance-maven-codegen/src/main/java/org/minbox/framework/api/boot/maven/plugin/mybatis/enhance/codegen/writer/JavaClassWriter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
package org.minbox.framework.api.boot.maven.plugin.mybatis.enhance.codegen.writer;
1919

20-
import java.io.BufferedWriter;
21-
import java.io.FileWriter;
22-
import java.io.IOException;
20+
import java.io.*;
2321

2422
/**
2523
* Java Class File Writer
@@ -33,6 +31,10 @@
3331
* GitHub:https://github.com/hengboy
3432
*/
3533
public class JavaClassWriter {
34+
/**
35+
* java file default charset
36+
*/
37+
private static final String DEFAULT_CHARSET_NAME = "UTF-8";
3638

3739
/**
3840
* Write code to entity classes
@@ -42,11 +44,11 @@ public class JavaClassWriter {
4244
*/
4345
public static void writeToJavaFile(String javaFilePath, String content) {
4446
try {
45-
FileWriter fw = new FileWriter(javaFilePath, false);
46-
BufferedWriter bw = new BufferedWriter(fw);
47+
OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(javaFilePath), DEFAULT_CHARSET_NAME);
48+
BufferedWriter bw = new BufferedWriter(writerStream);
4749
bw.append(content);
4850
bw.close();
49-
fw.close();
51+
writerStream.close();
5052
} catch (IOException e) {
5153
e.printStackTrace();
5254
}

0 commit comments

Comments
 (0)