You are here: Home > Download > Java code > Send advance message

Send Advance Message

    (get sources)

Message in other language

In order to send message in other language the text encoding should be 'UTF-8'.
The following application demonstrate how to read a file located on your local disk, encode it to 'UTF-8' and write the encoded file as a new file.
For more information please consult our detailed documentation

  import java.io.*;

  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) {
  // 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];
input.read(bytes, 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);
 
} finaly {
  if (input != null)
    input.close();
if (out != null)
    out.close();
 
}
   
   }