Java ByteBuffer to String

后端 未结 10 1612
一生所求
一生所求 2020-12-07 21:30

Is this a correct approach to convert ByteBuffer to String in this way,

String k = \"abcd\";
ByteBuffer b = ByteBuffer.wrap(k.getBytes());
String v = new Str         


        
10条回答
  •  不知归路
    2020-12-07 22:08

    private String convertFrom(String lines, String from, String to) {
        ByteBuffer bb = ByteBuffer.wrap(lines.getBytes());
        CharBuffer cb = Charset.forName(to).decode(bb);
        return new String(Charset.forName(from).encode(cb).array());
    };
    public Doit(){
        String concatenatedLines = convertFrom(concatenatedLines, "CP1252", "UTF-8");
    };
    

提交回复
热议问题