Code example for StringWriter

Methods: closetoString

0
        VelocityContext veCtx = new VelocityContext();
        veCtx.put(ctxName, ctx);
         
        // merge vm to email 
        BodyPart htmlPart = new MimeBodyPart(); 
        StringWriter htmlWriter = new StringWriter();
        html.merge(veCtx, htmlWriter);
        htmlWriter.close();
        htmlPart.setContent(htmlWriter.toString(), "text/html");
         
        BodyPart textPart = new MimeBodyPart();
        StringWriter textWriter = new StringWriter();
        text.merge(veCtx, textWriter);
        textWriter.close();
        textPart.setText(textWriter.toString());
         
        MimeMultipart multipart = new MimeMultipart("alternative");
        multipart.addBodyPart(textPart);		
        multipart.addBodyPart(htmlPart);
		return multipart;
Connect your IDE to all the code out there  Get Codota for Java