I have a text file with 2 lines of words
CCCCC,WIKY PODAR,130000,15
DDDDD,XXXXX555,130110,30
Program reads each line word by word spilt and store them into an array.
check myStringArray.length returns : 7
However I expect the output to be : 8
The issue is that two words at the end and the begining of the line are concatenated. How to seperate them and store into the array properly ?
String fileName = "mac/text.txt";
byte[] buffer = new byte[1000];
FileInputStream inputStream = new FileInputStream(fileName);
while (inputStream.read(buffer) != -1) {
String testString2 = new String(buffer);
String delim2 = ",";
String[] token2 = testString2.split(delim2);
String[] myStringArray = new String[token2.length];
for (int i = 0; i < token2.length; i++) {
myStringArray[i] = token2[i];
token2[i]=token2[i].replaceAll("\\s+", ", ");
}
System.out.println(myStringArray.length);