Jelajahi Sumber

u8凭证导出乱码优化

hxh 4 bulan lalu
induk
melakukan
11bd7f02e4
1 mengubah file dengan 9 tambahan dan 5 penghapusan
  1. 9 5
      src/custom/restcontroller/sale/cashbill/TxtFactory.java

+ 9 - 5
src/custom/restcontroller/sale/cashbill/TxtFactory.java

@@ -7,10 +7,7 @@ import common.YosException;
 import common.data.Row;
 import common.data.Rows;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.*;
 import java.util.*;
 
 public class TxtFactory {
@@ -26,7 +23,14 @@ public class TxtFactory {
 
     public void write(String str) throws YosException {
         try {
-            PrintWriter out = new PrintWriter(new FileWriter(this.filepath));
+            PrintWriter out = new PrintWriter(
+                    new BufferedWriter(
+                            new OutputStreamWriter(
+                                    new FileOutputStream(this.filepath),
+                                    "UTF-8"  // 关键:明确指定编码
+                            )
+                    )
+            );
 
             // 写入文本
             out.println(str);