I have written a java problem to split the data from a single column into tabular form. How can I use the same code in Talend's Java Component.
The input File will have a column which will have the data in the below format: 1:Apple;2:Manogo;3:Cheery;4:Berry;
The code that I have written in Java is :
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
public class DateDemo {
public static void main(String[] args) throws ParseException, IOException {
File file =new File("File.csv");
BufferedReader br = null;
br = new BufferedReader(new FileReader(file));
String line = "";
while ((line = br.readLine()) != null){
System.out.println(line);
String[] csvDataArray= line.split(";");
for(int i=0;i<csvDataArray.length;i++)
{
String[] csvData= csvDataArray[i].split(":");
String id = csvData[0];
String name = csvData[1];
System.out.println("ID "+id+" Name "+name);
}
}
}
}
The output which I get from this code is below :
ID 1 Name Apple
ID 2 Name Mango
ID 3 Name Cherry
ID 4 Name Berry
How can I implement the same in Talend.
I assume we have to use the components below : tfileinput---main---tJava--main--tFileoutput
But if i am pasting the above code in Tjava, it is giving me errors, while it is running fine in eclipse.
How can i achieve this in Talend.