【问题标题】:spring write string to file - spacing error春天将字符串写入文件 - 间距错误
【发布时间】:2019-11-05 14:30:19
【问题描述】:

在我的 Spring boot 应用程序中,我收到了String,现在我想将它们保存为特定目录中的文件。

我该怎么做?

我已经通过this,但它正在接收文件并保存,但我想写入那些文件。

我正在使用此代码,原始 JAVA:

PrintWriter writer = null;
        try {
            writer = new PrintWriter("file.txt", "UTF_32");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        writer.println(data);
        writer.close();

但这不是每个人都可能想要的,看看吧:

【问题讨论】:

    标签: spring spring-boot file


    【解决方案1】:

    看起来是你的字符编码,UTF_32。

    记事本不支持UTF_32,只支持ansi、UTF_8、UTF_16。

    见:

    Can Notepad read UTF-32?

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多