Multilingual UTF-8-encoding

In order to send messages in other languages, the text encoding should be ‘UTF-8’.

The following application demonstrates how to read a file located on your local disk, encode it to ‘UTF-8’ and write the encoded file as a new file.

package telemessage.test;

public class Test {
    public static void main(String[] args) {
        try {
            //encode inputFile to UTF-8 and write the encoded file to outputFile
            //assumption: the input file encoding is same as the file system default character - encoding,
            //To specify an encoding other than the default, you should change
            // 'System.getProperty("file.encoding")' to your file encoding.
            convertFileEncoding("input file path", System.getProperty("file.encoding"), "output file path", "UTF8");
        } catch (Exception e) {
            System.out.println("Unable to encode the contents of the request file." + e);

    public static void convertFileEncoding(String sourcefile, String inEncoding,String outfile, String outEncoding) throws IOException{
        // initialize
        InputStream input = null;
        OutputStream out = null;
        try {
            //Read sourcefile
            File infile = new File(sourcefile);
            input = new FileInputStream(infile);
            int bufLength = (int) infile.length();
            byte[] bytes = new byte[bufLength];
  , 0, bufLength);
            String s = new String(bytes, inEncoding);
            //Write outfile
            out = new FileOutputStream(new File(outfile));
            bytes = s.getBytes(outEncoding);
            out.write(bytes, 0, bytes.length);
        } finally {
            if (input != null)
            if (out != null)

Read more about encoding the subject line of an email.