TxtFactory.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package restcontroller.sale.cashbill;
  2. import beans.parameter.Parameter;
  3. import com.alibaba.fastjson2.JSONArray;
  4. import com.alibaba.fastjson2.JSONObject;
  5. import common.YosException;
  6. import common.data.Row;
  7. import common.data.Rows;
  8. import java.io.*;
  9. import java.nio.charset.StandardCharsets;
  10. import java.util.*;
  11. public class TxtFactory {
  12. private String filename;
  13. public static String filetype = "txt";
  14. String filepath = "";
  15. public TxtFactory(String filename) throws YosException {
  16. this.filename = filename + Calendar.getInstance().getTimeInMillis();
  17. String var10001 = Parameter.getExcelExportPath();
  18. this.filepath = var10001 + "/" + this.filename + "." + filetype;
  19. }
  20. public void write(String str) throws YosException {
  21. try {
  22. PrintWriter out = new PrintWriter(
  23. new OutputStreamWriter(
  24. new FileOutputStream(this.filepath),
  25. "GBK"
  26. )
  27. );
  28. // 写入文本
  29. out.println(str);
  30. // 确保所有缓冲的输出都被写出
  31. out.flush();
  32. // 关闭PrintWriter,虽然在这个例子中System.out不需要显式关闭
  33. out.close();
  34. out.flush();
  35. } catch (IOException var16) {
  36. var16.printStackTrace();
  37. }
  38. }
  39. public String getFilename() {
  40. return this.filename + "." + filetype;
  41. }
  42. public String getFilepath() {
  43. return this.filepath;
  44. }
  45. public File getFile() throws YosException {
  46. return new File(this.filepath);
  47. }
  48. public void deletefile() {
  49. File file = new File(this.filepath);
  50. file.delete();
  51. }
  52. }