Here you can find the source of toBytes(final String text)
Parameter | Description |
---|---|
text | String |
final public static byte[] toBytes(final String text)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Oak Ridge National Laboratory. * 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 ******************************************************************************/ public class Main { /** Convert String into byte array * @param text {@link String}// w w w. j a va2s.co m * @return byte array, always including '\0' termination */ final public static byte[] toBytes(final String text) { // Write string as byte array WITH '\0' TERMINATION! final byte[] bytes = new byte[text.length() + 1]; System.arraycopy(text.getBytes(), 0, bytes, 0, text.length()); bytes[text.length()] = '\0'; return bytes; } }