I have a requirement to read a pipe delimited file and have it populated in a String array and pass it as a list back and do further processing below.
Sample data : X|ABCD|001111006|1111006|ABC|test006| | | | | |C|||||||||||||
Note : Sample data can have both NULL and space between pipe
This is working fine if data is available in all the pipe delimits , atleast a space, but for the null values in between the pipe
There are 26 attributes and whenever there are NULL the array index is not incremented from the cardinal where NULL was available . Say when there is a NULL at 12 th pipe the array is not populated till 25 it stops at 12 and this is craeting issue in my further processing
and the file can have both NULL and space. Can you help me solve this issue
public List<String[]> readFile(String FileName) {
final List<String[]> userList = new ArrayList<String[]>();
BufferedReader bufferedreader = null;
try {
int i=0;
bufferedreader = new BufferedReader(new FileReader(FileName));
String line = null;
while ((line = bufferedreader.readLine()) != null) {
final String[] values = line.split("\\|");
userList.add(values);
}
}
catch (FileNotFoundException ex) {
CTLoggerUtil.logError(ex.getMessage());
}
catch (IOException ex) {
CTLoggerUtil.logError(ex.getMessage());
}
finally {
try {
if (bufferedreader != null)
{
bufferedreader.close();}
}
catch (IOException ex) {
CTLoggerUtil.logError(ex.getMessage());
}
}
return userList;
}