Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

read a csv file into a Java list

Hi,

I'm struggling to read a local file and get the contents into a java list for processing.

For example, the file might contain:

cat

dog

mouse

and the java list would be populated with these 3 values. 

I had assumed tfileinputdelimited would work but it always wants create name/value pairs whereas I just want a list of values.

 

Thanks

Andy

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Talend works using the concept of rows and columns. If you are reading data from a CSV file, that is data stored in a row/column fashion. However, you can assign your data into any Java object you like. Just use a tJavaFlex with code like this....

 

Start Code

// start part of your Java code
java.util.ArrayList<String> al = new java.util.ArrayList<String>();

Main Code

// here is the main part of the component,
// a piece of code executed in the row
// loop
al.add(row2.animal);

End Code

// end of the component, outside/closing the loop
globalMap.put("al", al);

In the above I am creating an ArrayList, assigning each row's "animal" column value to it and then storing the ArrayList in the globalMap to be used anywhere else in the job.

View solution in original post

2 Replies
Anonymous
Not applicable
Author

Talend works using the concept of rows and columns. If you are reading data from a CSV file, that is data stored in a row/column fashion. However, you can assign your data into any Java object you like. Just use a tJavaFlex with code like this....

 

Start Code

// start part of your Java code
java.util.ArrayList<String> al = new java.util.ArrayList<String>();

Main Code

// here is the main part of the component,
// a piece of code executed in the row
// loop
al.add(row2.animal);

End Code

// end of the component, outside/closing the loop
globalMap.put("al", al);

In the above I am creating an ArrayList, assigning each row's "animal" column value to it and then storing the ArrayList in the globalMap to be used anywhere else in the job.

TRF
Champion II
Champion II

Forget this, I didn't saw other messages.

How is configured your tFileInputDelimited component? It should have a single field in the schema.