Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File io 具有显式给定字符编码的Groovy WithWriter方法将销毁特定字符_File Io_Encoding_Groovy - Fatal编程技术网

File io 具有显式给定字符编码的Groovy WithWriter方法将销毁特定字符

File io 具有显式给定字符编码的Groovy WithWriter方法将销毁特定字符,file-io,encoding,groovy,File Io,Encoding,Groovy,我读了一个用Windows-1250编码的文件。我将每一行读入一个列表,然后执行一些附加操作并将集合存储到一个新文件中 问题。如果我显式地编写编码,那么输出文件似乎编码错误。如果我没有设置任何编码,则输出正常 enrichedFile.withWriter("windows-1250") { out -> tempFinalList.each() { line -> out.println line } } =>输出不良 enrichedF

我读了一个用Windows-1250编码的文件。我将每一行读入一个列表,然后执行一些附加操作并将集合存储到一个新文件中

问题。如果我显式地编写编码,那么输出文件似乎编码错误。如果我没有设置任何编码,则输出正常

enrichedFile.withWriter("windows-1250") { out ->
     tempFinalList.each() { line ->
          out.println line
     } 
}
=>输出不良

enrichedFile.withWriter { out ->
     tempFinalList.each() { line ->
         out.println line
     }
}
=>好的


仅供参考:我将其用于捷克语,字母为:ěšřýáé。

我看不出有任何问题

def myFile = new File('./Archive/file.txt')
def tempFinalList = []

//Reading from the file with windows charset
myFile.withReader('windows-1250') { out ->
    out.eachLine{
        tempFinalList << it
    }
}

//Appending stuff
tempFinalList << 'a' << 'b'

//Creating a new file
def newFile = new File('./Archive/NewFile.txt')

//Writing to the new file with windows charset
newFile.withWriter('windows-1250'){out ->
    tempFinalList.each{out.writeLine it}
}

newFile.eachLine{println it}

我看不出有什么问题

def myFile = new File('./Archive/file.txt')
def tempFinalList = []

//Reading from the file with windows charset
myFile.withReader('windows-1250') { out ->
    out.eachLine{
        tempFinalList << it
    }
}

//Appending stuff
tempFinalList << 'a' << 'b'

//Creating a new file
def newFile = new File('./Archive/NewFile.txt')

//Writing to the new file with windows charset
newFile.withWriter('windows-1250'){out ->
    tempFinalList.each{out.writeLine it}
}

newFile.eachLine{println it}