Android查看文本文件问题 [英] Android view text file issue
问题描述
我可以在textview中看到我的文本文件,但是我希望以与在屏幕上看不到我的文件相同的方式进行打印...
我要查看文件的代码是
尝试{
资源res = getResources();
InputStream in_s = res.openRawResource(R.raw.report);
byte [] b =新的byte [in_s.available()];
in_s.read(b);
read.setText(new String(b));
} catch(Exception e){
//e.printStackTrace();
// 这是textview设置的文本文件视图
read.setText(错误:无法显示帮助.");
I can see my text file in textview but i want to print in same manner as in file which is not seeing me on screen ...
my code to see file is
try {
Resources res = getResources();
InputStream in_s = res.openRawResource(R.raw.report);
byte[] b = new byte[in_s.available()];
in_s.read(b);
read.setText(new String(b));
} catch (Exception e) {
// e.printStackTrace();
//this is textview set text file view
read.setText("Error: can''t show help.");
推荐答案
// try opening the myfilename.txt
try {
// open the file for reading
InputStream instream = openFileInput("myfilename.txt");
// if file the available for reading
if (instream) {
// prepare the file for reading
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
// read every line of the file into the line-variable, on line at the time
while (( line = buffreader.readLine())) {
// do something with the settings from the file
}
}
// close the file again
instream.close();
} catch (java.io.FileNotFoundException e) {
// do something if the myfilename.txt does not exits
}
这篇关于Android查看文本文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!