I’m trying to import a text file to simply display in a textview using android.
The file is called “legal” and is located in res/raw
I use the following code to read in the file…
BufferedReader bufferreader = new BufferedReader(new
InputStreamReader(getResources().openRawResource(R.raw.legal), Charset.forName("UTF8")));
String bufferLine;
String tempText = "";
try
{
while ((bufferLine = bufferreader.readLine()) != null)
{
tempText = tempText + bufferLine + "\n";
}
}
catch (IOException e)
{
e.printStackTrace();
}
When I try to display tempText in a TextView, directional “smart” quotes are displayed as as unknown characters. The text file, legal, is encoded with UTF8 (used notepad++). I can’t seem to figure out what the problem is.
Are you sure “UTF8” is a valid charset name? the documentation for Charset seems to suggest UTF-8
I usually just do
and haven’t had any problems. I have had problems with utf encoded html style. As in
&#UNICODENUMBER;This fixed those problems
EDIT
Since the above didn’t help you I would try the following:
Just to see if the font used has support for the characters (I’m guessing you are after curling quotes). If it does render, there must be a issue with either the way you read the file (even-though, it looks valid enough), or the actual file.
Hope that helps 🙂