Obviously, textoFormado
is a variable of type String
. This means that the bytes were already decoded. Java then internally uses a 16-bit Unicode representation. What you did, is to encode your string with Windows-1252 followed by reading the resulting bytes with an UTF-8 encoding. That does not work.
What you need is the correct encoding when reading the bytes:
byte[] sourceBytes = getRawBytes();
String data = new String(sourceBytes , "Windows-1252");
For using this string inside your program, you do not need to do anything. Simply use it. If - however - you want to write the data back to a file for example, you need to encode again:
byte[] destinationBytes = data.getBytes("UTF-8");
// write bytes to destination file here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…