//按行讀取文本 java
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();
} get
注意 若是substring(index1,index2)中的index2若是大於str.length()+1則會報出異常java.lang.StringIndexOutOfBoundsException: String index out of range string