Advertisement
lope3x

Untitled

Feb 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. public static String UTF8toISO(String str){
  2.         Charset utf8charset = Charset.forName("UTF-8");
  3.         Charset iso88591charset = Charset.forName("ISO-8859-1");
  4.  
  5.         ByteBuffer inputBuffer = ByteBuffer.wrap(str.getBytes());
  6.  
  7.         // decode UTF-8
  8.         CharBuffer data = utf8charset.decode(inputBuffer);
  9.  
  10.         // encode ISO-8559-1
  11.         ByteBuffer outputBuffer = iso88591charset.encode(data);
  12.         byte[] outputData = outputBuffer.array();
  13.  
  14.         return new String(outputData);
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement