Skip to main content

Posts

Showing posts from November, 2014

java numbers to Text Statement

package ms.utils; import java.text.DecimalFormat; public class EnglishDecimalFormat { private static final String[] majorNames = {    "",    " Thousand",    " Million",    " Billion",    " Trillion",    " Quadrillion",    " Quintillion"    };  private static final String[] tensNames = {    "",    " Ten",    " Twenty",    " Thirty",    " Fourty",    " Fifty",    " Sixty",    " Seventy",    " Eighty",    " Ninety"    };  private static final String[] numNames = {    "",    " One",    " Two",    " Three",    " Four",    " Five",    " Six",    " Seven",    " Eight",    " Nine",    " Ten",    " Eleven&q

java html to pdf

package testpdf; import com.itextpdf.text.Document; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.tool.xml.XMLWorkerHelper; import java.io.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; public class HtmlToPdf {     public static void main(String[] args)             throws IOException { try {         String content = readFile("c:/temp/html.html", StandardCharsets.UTF_8);     OutputStream file = new FileOutputStream(new File("C:/temp/Test.pdf"));     Document document = new Document();     PdfWriter writer = PdfWriter.getInstance(document, file);     document.open();     InputStream is = new ByteArrayInputStream(content.getBytes());     XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);     document.close();     file.close(); } catch (Exception e) {     e.printStackTrace(); }                           }         static Str

Java send email with attachment via exchange server

      public void sendMailWithAttachment(String from,List<String> toList, String subject ,String body,String filePath) throws MessagingException{          Properties props = new Properties(); props.put("mail.smtp.host", "exchange.company.com");//         props.put("mail.smtp.user", "sender user name");         props.put("mail.smtp.password", "sender password"); //mail.smtp.ssl.enable         props.put("mail.smtp.ssl.enable", "false"); Session session = Session.getDefaultInstance(props, null); session.setDebug(true); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from));         InternetAddress ia=null;         List<InternetAddress> addresees=new ArrayList<InternetAddress>();         for(String to :toList ){             ia=new InternetAddress(to);             addresees.add(ia);         }         InternetAddress[] array = new InternetAddress[add

Java Date Formatter table

G Era designation Text AD y Year Year 1996 ; 96 M Month in year Month July ; Jul ; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d Day in month Number 10 F Day of week in month Number 2 E Day in week Text Tuesday ; Tue a Am / pm marker Text PM H Hour in day ( 0 - 23 ) Number 0 k Hour in day ( 1 - 24 ) Number 24 K Hour in am / pm ( 0 - 11 ) Number 0 h Hour in am / pm ( 1 - 12 ) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time ; PST ; GMT - 08 : 00 Z Time zone RFC 822 t