Java – Generate CSV from Java Bean using OpenCSV

Download OpenCSV: http://sourceforge.net/projects/opencsv/files/latest/download

OpenCSV is a free and open source library for reading and writing CSV files in Java. We need to have latest opencsv jar in classpath. Following example shows generating a CSV from java beans using opencsv.

Bean2CSV.java

Student.java

Output:

Generated CSV :
“name”,”age”
“Mayur”,”25″
“Vishal”,”26″


Java – Generic Interface Example

MinMax.java

MyClass.java

GenIFDemo.java


Java Struts – Logging with Log4j Example

Download Log4j: http://logging.apache.org/log4j/index.html

Log4j Appender:
Create a Log4j properties file (log4j.properties) and define the appender details (where to log and log file details). And put the log4j.properties into your project classpath.

log4j.properties

Struts Action Class:

Struts Custom Exception Handler:

Log4j Output File Sample- c:\\logging.log