import com.opencsv.CSVReader;
public class CSVReaderExample {
public static void main(String[] args) {
try (CSVReader reader = new CSVReader(new FileReader("data.csv"))) {
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
for (String field : nextLine) {
System.out.print(field + " ");
}
System.out.println();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
import com.opencsv.CSVWriter;
public class CSVWriterExample {
public static void main(String[] args) {
try (CSVWriter writer = new CSVWriter(new FileWriter("output.csv"))) {
String[] record1 = {"John", "Doe", "john.doe@example.com"};
String[] record2 = {"Jane", "Smith", "jane.smith@example.com"};
writer.writeNext(record1);
writer.writeNext(record2);
System.out.println("Data written successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
}