//按行读取文本
String FileName="d:/txt.txt";
File myFile=new File(FileName);try
{
BufferedReader in = new BufferedReader(new FileReader(myFile));
String str;
while ((str = in.readLine()) != null&& in.readLine() != "")
{
String N = str;
for (int i = 0; i < N.length()-1; i++) { //循环读取文本的每一行
String string = "**";
if (str.substring(i, i+2).equals(string)) {//跟进需要截取所需要的字符串
System.out.println(str.substring(i+2, N.length()));
}
}
}
in.close();
}
catch (IOException e)
{
e.getStackTrace();
}
注意 如果substring(index1,index2)中的index2如果大于str.length()+1则会报出异常java.lang.StringIndexOutOfBoundsException: String index out of range