Here you can find the source of getUTF8(String string)
Parameter | Description |
---|---|
string | Java string |
public static byte[] getUTF8(String string)
//package com.java2s; /*/*from w w w . j a v a 2 s .co m*/ * Copyright 2009 Tim Krajcar <allegro@conmolto.org>. * * This file is part of Koom, a BattleTech MUX graphical HUD client. * * Koom is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Koom is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Koom. If not, see <http://www.gnu.org/licenses/>. */ import java.io.UnsupportedEncodingException; public class Main { /** * Encodes a string as an array of UTF-8 bytes. Mostly used to pre-encode * constants. * * @param string * Java string * * @return UTF-8 byte array */ public static byte[] getUTF8(String string) { try { return string.getBytes("UTF-8"); } catch (UnsupportedEncodingException ex) { // All JVMs should support UTF-8. throw new AssertionError(ex); } } }