Groovy 写下;美国国家标准协会;编码文件到磁盘

Groovy 写下;美国国家标准协会;编码文件到磁盘,groovy,encoding,cp1252,Groovy,Encoding,Cp1252,我应该使用ANSI格式的groovy创建一个导出文件。 当我将文件写入磁盘并在“记事本++”或nano中打开时,“äüö”等特殊字符没有正确显示。 Notepad++将“Windows-1255”显示为编码 我已经尝试过更改编码并另外转换字符串 import java.io.FileWriter import java.io.BufferedWriter import java.io.InputStream import java.nio.charset.Charset import java.

我应该使用ANSI格式的groovy创建一个导出文件。 当我将文件写入磁盘并在“记事本++”或nano中打开时,“äüö”等特殊字符没有正确显示。 Notepad++将“Windows-1255”显示为编码

我已经尝试过更改编码并另外转换字符串

import java.io.FileWriter
import java.io.BufferedWriter
import java.io.InputStream
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets


String fullPath = "/tmp/jamesTempFiles/ansi.txt"

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fullPath), "Cp1252"))
//doesn't work either when i use the following line instead
//BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fullPath), "windows-1252"))
String input = "test\r\näüöß"

writer.write(input)
//doesn't work either when i use the following line instead
//writer.write(new String(input.getBytes(Charset.forName("utf-8"))))
writer.close()
在Notepad++中,该文件如下所示 第二行中的字符应为:
äüöß

我想我可能是被记事本++中的一个bug绊倒了。
将测试字符串更改为实际数据时,notepad++确实开始将特殊字符解释为例外。

我想我可能是无意中发现了notepad++中的一个错误。
将测试字符串更改为实际数据时,notepad++确实开始将特殊字符解释为例外。

代码中的一切都很好。ansii文件没有任何标记来检测编码,所以您应该手动执行。在notepad++中是
encodong-charsets-centraleuropean-1250
代码中的一切都很好。ansii文件没有任何标记来检测编码,所以您应该手动执行。在记事本++中,它是
encodong-charsets-centraleuropean-1250