Welcome back.
We loaded the model and converted it as a byte buffer.
Now let's load the labels.
So, as I told you before, we need to load the model and the labels here.
Okay.
So for that create a new function.
Name it as load labels.
And this function takes a file name as a string returning a list of string.
And this will return.
Try val input stream equals to context dot assets dot.
Open the file name.
Then we need a buffered reader.
So val buffered reader equals to the input stream dot bufferedreader.
Or we can make it like this buffered reader.
We need to create an input stream reader, input stream reader and pass the input stream.
Then use the Bufferedreader dot read lines.
This code will read a text file from assets, which is this cocoa database data set underscore labels
dot txt file and returns it content as a list of strings.
We need to return them as lines.
So here if we open it we need to return them as lines.
So for this purpose we used Inputstream Bufferedreader and we pass the input stream reader.
This will read a text file from assets line by line, returning a list of string where each element
is one line of the file and automatically handles character encoding and line breaks.
The input stream context ascites dot open appends the file as a row input stream from the apps assets
folder.
Returns a basic byte stream without any character encoding and decoding.
The input stream reader converts the raw byte stream into a character stream.
Handles character encoding.
Uses platforms the default encoding if not specified, and can specify encoding explicitly like UTF
eight here, so I can specify it here, like use the dash eight.
Okay, but I don't want from for this example because it's very simple.
And the byte buffer or buffered reader wraps the input stream reader to provide buffering improves performance
by reading large chunks at once, and provides convenient line reading methods and read lines.
Here, the method reads all lines from the file into a list of strings.
Each line is stripped of line termination character.
The reader is automatically closed after reading if using use block.
Okay, this is how we read a text file from assets and returns its content as a list of strings.
Let me surround this with catch block with E for exception and log the loaded labels okay and return
an empty list in case of failure.