简体   繁体   中英

UTF8 encoding issue in scala

I need help with the encoding to UTF-8. I am trying to populate few data in db using scala. I used the following code to convert the field to UTF-8.

def formatElement(value : String) : String = {
        var strValue = new String(java.util.Arrays.copyOfRange(value.getBytes("UTF-8"), 0, value.getBytes("UTF-8").length), "UTF-8");
        strValue;
    }

But the problem is the encoding done properly. For example:

Fülöpszállás getting saved as Fülöpszállás
Zablaće getting saved as ZablaÄe

I am using maven to compile and in pom.xml I have added

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

under "property" node

On analyzing the issue I have found out the reason. I have different file.encoding set in my websphere server. So the code is not required as the encoding is handled by the server itself. No matter in which format I encode my string it will get encoded to the format which is mentioned in the server. Thanks for your effort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM