Here you can find the source of toUTF(String str)
public static byte[] toUTF(String str) throws RuntimeException
//package com.java2s; /*//from w w w . j a v a 2 s . co m * Copyright (c) 2015 Eike Stepper (Berlin, Germany) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Eike Stepper - initial API and implementation */ import java.io.UnsupportedEncodingException; public class Main { public static final String UTF8 = "UTF-8"; private static final byte[] NO_BYTES = {}; public static byte[] toUTF(String str) throws RuntimeException { if (str == null) { return null; } if (str.length() == 0) { return NO_BYTES; } try { return str.getBytes(UTF8); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } } }