我想在android中读取一个文本文件。我正在尝试这段代码。
public class GIF_Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gif_);
try {
PlayWithRawFiles();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"Problems: " + e.getMessage(), 1).show();
}
}
public void PlayWithRawFiles() throws IOException {
String str="";
StringBuffer buf = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.drawable.abc);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is!=null) {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n" );
}
}
is.close();
Toast.makeText(getBaseContext(),
buf.toString(), Toast.LENGTH_LONG).show();
}
}
但不是让文件显示在屏幕上,而是在烤文件。请帮我阅读完整的文件。提前致谢。