/* FileToHex v1.2 Hex encodes all files in a particular directory for use with WapMX SMS Server. Hex encoded files will be saved with a ".hex" extension. Contact support@wapMX.com if you experience any problems. Usage: java FileToHex c:\temp */ import java.io.*; public class FileToHex { public static void main (String[] args) { String directory = args[0]; File dir = new File(directory); File[] files = dir.listFiles(); for (int fileCount = 0 ; fileCount < files.length ; fileCount++) { if (files[fileCount].isDirectory() == false) { System.out.println("Hex Encoding: " + files[fileCount]); String hexByte = ""; String hexTotal = ""; try { RandomAccessFile inputfile = new RandomAccessFile(files[fileCount], "r"); FileOutputStream outputfile = new FileOutputStream(files[fileCount] + ".hex", true); PrintStream out = new PrintStream(outputfile); for (int i = 1 ; i <= inputfile.length() ; i++) { hexByte = Integer.toHexString(inputfile.read()).toUpperCase(); if (hexByte.length() == 1) hexByte = "0" + hexByte; hexTotal = hexTotal + hexByte; } out.println(hexTotal); out.flush(); out.close(); outputfile.close(); inputfile.close(); } catch (FileNotFoundException fnfe) { System.out.println(fnfe); } catch (IOException ioe) { System.out.println(ioe); } } } } }