I want to read all CSV files that are in one folder and then sort them by the Field named 'Name'.
What is the best way to do so?
input files example:
File1:-
address,name,custnum
190 vikign,Cname,123455
1555 oakbroo,BName,123455
1234 sprint st,EName,123455
File2:-
address,name,custnum
190 sprint,Wname,123455
1555 windy hill,AName,123455
1234 sprint st,BName,123455
One OutPut File like:-
address,name,custnum
1555 windy hill,AName,123455
1555 oakbroo,BName,123455
1234 sprint st,BName,123455
190 vikign,Cname,123455
1234 sprint st,EName,123455
190 sprint,Wname,123455
My Code so far:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.regex.Pattern;
public class MoniLetterOwnmanSorting1 {
/**
* @param args
*/
public static void delFileFromDir(String dirPath) {
File dir = new File(dirPath);
if (dir.listFiles() == null)
return;
for (File file : dir.listFiles()) {
if (!file.isDirectory())
file.delete();
}
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = null;
BufferedWriter bfAll = null;
File folder = new File("OwnmanFileIn");
File[] BFFile = folder.listFiles();
String count = "OwnmanFileOut\\" + "OwnmanFileSort.csv";
bfAll = new BufferedWriter(new FileWriter(count));
for (File file : BFFile) {
br = new BufferedReader(new FileReader(file));
String line;
line = br.readLine();
while((line = br.readLine()) != null) {
String[] actionID = line.split("\\,");
String name= actionID[1].replace("\"", "");
//PLEASE HELP ME!!
}
}
}
}