UIWebView supports text file display. You can use the following code to load text files:
[
Unfortunately, for Chinese, UIWebView does not support very well:
The 48_1.txt file contains Chinese characters. We do not know what encoding it is. It may be UTF8, GBK, or GB18030. We can infer its encoding through the stringWithContentsOfFile method:
{
Encoding = 0x80000632;
Body = [
}
Encoding = 0x80000631;
Body = [
}
Replace them with UTF16 encoding and save them to a new file:
[InData
}
}
Note that the pathForTemporaryFile function is customized. It actually points the file to the temp folder of the sandbox.
In this way, UIWebView can correctly display Chinese characters:
But I don't know why, when UIWebView displays a text file, several bytes at the end of the file are displayed as squares. These squares are actually some "\ 0" characters. When I open the 48_1.txt file using a text editor or TextMate program, these "\ 0" characters are not displayed on the screen. However, in UIWebView, they are displayed as squares. Therefore, you can add the following code before saving the file:
Body = [body
In this way, you can remove those blocks.