我正在尝试使用 substrings 和 bufferedreader 提取两个标签之间的文本,但出现 indexoutofbounds 异常。使用 if 语句是因为我正在解析 5 个网页,并且我想从每个网页中读取文本,下面是我的代码:
public static List<WebPage> readRawTextFile(Context ctx, int resId) {
InputStream inputStream = ctx.getResources().openRawResource(
R.raw.pages);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line;
StringBuilder text = new StringBuilder();
String txt1 = text.toString();
try {
int count = 0;
while ((line = buffreader.readLine()) != null) {
if (line.length() == 0) {
int sURL = line.indexOf("<!--");
int eURL = line.indexOf("-->");
String newSub = txt1.substring(txt1.indexOf(sURL) + 1,
txt1.indexOf("\""));
System.out.println(newSub);
}