Java – How to fax two files

Note that this is a deprecated sample. Please review the Java fax code samples section for newer samples.

Download the Java project files.

class TestFax {  public static void main(String[] args) throws Exception {
String str1 = "First test fax.";
String str2 = "Second test fax.";

//Concat the Strings in order to use the Web Service
String testStr = str1.concat(str2);

Integer len1 = new Integer(str1.length());
Integer len2 = new Integer(str2.length());
int testStrLen = testStr.length();

String fileLen = len1.toString().concat(";").concat(len2.toString());

byte[] b = new byte[testStrLen];
for (int i=0;i 0)
    // Positive result indicates that the fax was sent successfully.
    // The return value is the TransactionID.
    System.out.println("Fax was sent successfully. Transaction number: " + result);
    else
    //Fax sending failure.
    System.out.println("Error sending fax!" + result);
    }

catch(Exception e) {

    System.out.println(e.toString()); 

} } }