I am trying to read a .txt
file that has tree structure with tabs and
i want to convert it in a .csv
.
Category
Subcategory
Subcategory1
Subcategory11
Item1
Item2
Subcategory12
Item1
Subcategory13
Item1
Item11
I want to create a .csv
file with the structure
Category, Subcategory,Subcategory1, Subcategory11,Item1
Category, Subcategory,Subcategory1, Subcategory11,Item2
Category, Subcategory,Subcategory1, Subcategory12,Item1
Category, Subcategory,Subcategory1, Subcategory13,Item1,Item11
What i have done so far is that
public static void main(String[] args) throws IOException {
Scanner keywords = new Scanner(new File("keywords.txt"));
ArrayList<ArrayList<String>> keywordsList = new ArrayList<ArrayList<String>>();
ArrayList<String> newline = new ArrayList<String>();
while(keywords.hasNext()){
String line = keywords.nextLine();
String[] tokens = line.split("\t");
for(int i=0; i<tokens.length; i++){
if(tokens[i] != null && !tokens[i].isEmpty()){
newline.add(tokens[i]);
}
}
keywordsList.add(newline);
}
}