Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
//Below we create a HashMap which will contain FileOutputStream objects
java.util.HashMap<String, java.io.FileOutputStream> fileOutputStreamMap = new java.util.HashMap<String, java.io.FileOutputStream>();
//Set the groupKey variable
String groupKey = row1.newColumn;
//Create your file row by concatenating the values in the row to a String
String tmpVal = groupKey +";"+
row1.newColumn1 +";"+
row1.newColumn2 +";"+
row1.newColumn3 +";"+
row1.newColumn4 +";"+
row1.newColumn5 +";"+
row1.newColumn6+"\n";
//Convert the String to a byte array
byte[] contentInBytes = tmpVal.getBytes();
//If the FileOutputStream for the groupKey exists do below...
if(fileOutputStreamMap.containsKey(groupKey)){
fileOutputStreamMap.get(groupKey).write(contentInBytes);
}else{ //If the FileOutputStream for the groupKey does not exist, do below...
//create a new FileOutputStream for the groupKey and add it to the HashMap
fileOutputStreamMap.put(groupKey, new java.io.FileOutputStream("C:/Talend/OpenSource/6.2/TOS_BD-20160510_1709-V6.2.0/workspace/"+groupKey+".csv",false));
//write to the file
fileOutputStreamMap.get(groupKey).write(contentInBytes);
}
//Create an Iterator for the HashMap keyset
java.util.Iterator<String> it = fileOutputStreamMap.keySet().iterator();
//Iterate over the HashMap Key Set and close the FileOutputStreams
while(it.hasNext()){
java.io.FileOutputStream tmpStream = fileOutputStreamMap.get(it.next());
tmpStream.close();
}
@whiteand72 Is this resolved ??
could you please let me know the solution .I also want to do similar thing ..In which
I am extracting the data from oracle table after the partitioning it based on key and writing final files in MFS directory
I got that partition part but not sure how to write in multi files like as of Abinitio
Please help and suggest