以上帝的名义
你好,我有一个文本文件,想要读取并显示到 textview 中,奇数行和偶数行使用不同的字体和颜色,如何更改此读取代码:
代码 :
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"komeil.txt");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
text.append('\n');
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
像这个文本文件:
文件 :
hello people i am student //black
i want to rad this file //green
different color //black
different font //green
how to do this //black
... //green
... //black
. //green
. //black
. //green