Convert ISO-8859-1 to UTF-8 using groovy

后端 未结 2 2287
情歌与酒
情歌与酒 2021-02-14 09:24

i need to convert a ISO-8859-1 file to utf-8 encoding, without loosing content intormations...

i have a file which looks like this:



        
2条回答
  •  没有蜡笔的小新
    2021-02-14 10:05

    Making it a little more Groovy, and not requiring the whole file to fit in memory, you can use the readers and writers to stream the file. This was my solution when I had files too big for plain old Unix iconv(1).

    new FileOutputStream('out.txt').withWriter('UTF-8') { writer ->
        new FileInputStream('in.txt').withReader('ISO-8859-1') { reader ->
            writer << reader
        }
    }
    
    • http://www.hjsoft.com/blog/link/A_Useful_Example_in_Java_Ruby_and_Groovy

提交回复
热议问题