I am quiet new to java and below is my java code. When I execute this java program I am getting an exception as
java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
I have already find out the reason why i am getting error.
When i open this csv file in normal text editor then i dont see any issue with the data. But when i try to open the file in VI editor in Ubuntu then i can see there is ^M line character and this is causing the exception. When i edit the file and remove the ^M and run the program again then its working fine and inserting data into table.
It is the line break on Windows PCs which is being read as ^M in VIM based editors and i am getting this file from windows and i am reading this in ubuntu.
Here is the screenshot where i can see ^M and it is at the index 4.
I see replaceAll
function in java but i dont know how to use it and where exactly i need to use it. I only need to remove ^M
and read the file.. Please help
I tried with condition String line = line1.replaceAll("^M","");
but still getting same exception. I am not sure is there any other way to handle this in exception or other logic