Java String to Byte Array getBytes(String s)

Here you can find the source of getBytes(String s)

Description

Returns the bytes of the string in ENCODING_ISO_8859_1.

License

Open Source License

Parameter

Parameter Description
s a parameter

Return

a byte[] representation of the string in ISO_8859_1 encoding.

Declaration

public static byte[] getBytes(String s) 

Method Source Code


//package com.java2s;
/*/*  w ww . j a va 2s  .c om*/
 *  PHEX - The pure-java Gnutella-servent.
 *  Copyright (C) 2001 - 2007 Phex Development Group
 *
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 *  --- SVN Information ---
 *  $Id: StringUtils.java 4284 2008-10-25 14:24:14Z gregork $
 */

import java.io.UnsupportedEncodingException;

public class Main {
    public static final String ENCODING_ISO_8859_1 = "ISO-8859-1";

    /**
     * Returns the bytes of the string in ENCODING_ISO_8859_1.
     * In case a exception is raised standard s.getBytes() is called.
     *
     * @param s
     * @return a byte[] representation of the string in ISO_8859_1 encoding.
     */
    public static byte[] getBytes(String s) {
        try {
            return s.getBytes(ENCODING_ISO_8859_1);
        } catch (UnsupportedEncodingException e) {
            return s.getBytes();
        }
    }
}

Related

  1. convertStringToBytes(String string)
  2. getBytes(String k)
  3. getBytes(String k)
  4. getBytes(String outputFile, Map queries)
  5. getBytes(String s)
  6. getBytes(String s)
  7. getBytes(String s)
  8. getBytes(String s)
  9. getBytes(String s)