I have a CSV file which contains almost 10000 lines of data. I want to split that file into 10 different CSV file based on the total line count, so that each file can contain 1000 lines of data in the order first file should have 1-1000 lines, second file should have 1001-2000 lines and so on. Also, each of those 10 different CSV file should only contain the data from the first column of the parent CSV file. The code which I developed writes the same data (1.e 1-1000 lines) to all of the 10 csv files. I am unable to figure out what is the mistake in the code.
for (int j=1;j<=files;j++){
String inputfile = "C:/Users/Downloads/File.csv";
BufferedReader br = new BufferedReader(new FileReader(inputfile));
FileWriter fstream1 = new FileWriter("C:/Users/Downloads/FileNumber_"+j+".csv");
BufferedWriter out = new BufferedWriter(fstream1);
String strLine = null;
for (i=i+1;i<=(j*lines);i++) { //I Have declared i as static int i = 0 and have already calculated lines and files in other part of code
strLine = br.readLine();
if (strLine!= null) {
String strar[] = strLine.split(",");
out.write(strar[0]);
if(i!=(j*lines)) {
out.newLine(); }
}
}
out.close();