import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class ReadTxt {
File file = new File("e://text.txt");
public static void main(String[] args) throws Exception {
File file = new File("e://text.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = "";
while ((line = reader.readLine()) != null) {
if(line.substring(0,3).equals("***"))
{
System.out.println(line);
}
}
}
}
public static void main(String[] args) throws Exception {
File file = new File("D://text.txt");
BufferedReader br= new BufferedReader(new FileReader(file));
String line = "";
while ((line = br.readLine()) != null) {
if(line.startsWith("***")) {
System.out.println(line);
}
}
}
读取一行,记为字符串x;
识别字符:识别x的开头是否为*,并同时计数;
若是*,计数加1;
当连续计数为3时,将x计入数组z;
若否,计数为0;继续下一行读取;
输出数组z。
是不是 到空格为止? 如果是的话 正则 就这么写 \*\*\*\S+ 匹配 ***后面加不是空格的任意长度字符串
input.startsWith("***"); 用startsWith()这个函数就可以了