我已经设置了类似下面解析文件/ Android的
Title - Welcome to the Dibb
Date - 13/03/11
Information - Hello and welcome to our website.
Title - Welcome to student room
Date - 06/05/11
Information - Hello and welcome to the student room. We are a online forum that allows previous and current students to ask questions.
一个文本文件,我需要解析这个文本文件,并保存之类的标题行,日线,其余的将被保存为信息。我知道如何读取文件并将整个文件保存为字符串,但我一直在获取选择信息。
CODE
这是我用来读取文本文件中的代码
helloTxt.setText(readTxt());
}
private String readTxt() {
InputStream inputStream = getResources().openRawResource(R.raw.pages);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1) {
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String str = byteArrayOutputStream.toString();
return str;
}
看起来好像你可以在第一次之后分开。有什么问题吗? –
感谢您的建议,但我需要整行,所以我不能在 - –
后溢出“但我需要整行,所以我不能在后面溢出 - ”如果您需要全行,您将如何提取字段? –