title: encoding xlsx as base64 and send it as an attachment
body: <p>I have an assignment where i need to create a .xlsx and convert it to base64 and this file will sent as an attachment in an email webservice.The code for conversion of .xlsx to base64 is as below:</p>
  
  <pre><code>import java.io.*;
  
  import org.apache.commons.codec.binary.Base64;
  
  public class Test {
    public static void main(String [] args) {
  
       String fileName = "C:/Users/kk.txt";
  
      try {
            byte[] buffer = new byte[1000];
  
          FileInputStream inputStream = 
              new FileInputStream(fileName);
  
          int total = 0;
          int nRead = 0;
          String reference=null;
          while((nRead = inputStream.read(buffer)) != -1) {
                             String name=(new String(buffer));
              byte[] encodedBytes = Base64.encodeBase64(name.getBytes());
  
              System.out.println(new String(encodedBytes));
  
          }   
  
        inputStream.close();      
  
        System.out.println("Read " + total + " bytes"); 
      }
      catch(FileNotFoundException ex) {
          System.out.println(
              "Unable to open file '" + 
              fileName + "'");                
      }
      catch(IOException ex) {
          System.out.println(
              "Error reading file '" 
              + fileName + "'");                  
          // Or we could just do this: 
          // ex.printStackTrace();
      }
    }
  }
  </code></pre>
  
  <p>but when i send it as a mail using BPEL and when i open the file it shows general input/output error.But when i send it as a text it works fine. Should i not use this code for excel or where am i wrong.Am totally new to java.</p>