Java - Write code to Convert a String filename to a byte array using the deprecated ascii String method

Requirements

Write code to Convert a String filename to a byte array using the deprecated ascii String method

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String fileName = "book2s.com";
        System.out.println(java.util.Arrays
                .toString(stringToBytes(fileName)));
    }//from   w  ww.  j  a v  a 2s.  c  om

    /**
     * Convert a <code>String</code> filename to a byte array using the
     * deprecated ascii String method for cases where passing it through
     * a character set converter is too heavyweight.
     *
     * @param fileName File name
     * @return Byte-array representation
     */
    @SuppressWarnings("deprecation")
    public static byte[] stringToBytes(String fileName) {
        byte[] asciiName = new byte[fileName.length()];
        fileName.getBytes(0, fileName.length(), asciiName, 0);
        return asciiName;
    }
}