Question: Having problems trying to write the result in CSV files. When I read the file its fine but when I write it to a new

Having problems trying to write the result in CSV files. When I read the file its fine but when I write it to a new CSV file I am seeing duplicates.

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.io.PrintWriter;

- - - - Code - - - -

public class cvsreader {

String domain;

public static void main(String[] args) throws IOException {

String line;

BufferedReader br = new BufferedReader(new FileReader("original.csv"));

PrintWriter pw = new PrintWriter(new File("new.csv"));

StringBuilder sb = new StringBuilder();

while ((line = br.readLine()) != null) {

String[] emp = line.split(" ");

String email = ("Hello " + emp[0] );

System.out.println(email);

sb.append(email);

sb.append(' ');

pw.write(sb.toString());

}

pw.close();

}

}

- - - - CSV File - - - -

World

Galaxy

Universe

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!