正好前几天温故了下IO这块的知识,随便帮你写一个练练手。
package comhqhtest;
import javaioBufferedReader;
import javaioFileInputStream;
import javaioInputStreamReader;
public class ReadFile {
public static void readFile(String file) throws Exception{
FileInputStream fis=new FileInputStream(file);
BufferedReader bf = new BufferedReader(new InputStreamReader(fis));
String line = bfreadLine();
while((line=bfreadLine())!=null){
String start ="AB:";
//如果本行是以start开头
if(linestartsWith(start)){
//获取最后面一个冒号后面的字符串
String lastString = linesubstring(linelastIndexOf(":")+1);
Systemoutprintln(lastString);
}
}
fisclose();
}
/
@param args
/
public static void main(String[] args) {
try {
readFile("C:\\testtxt");
} catch (Exception e) {
eprintStackTrace();
}
}
}
testtxt文件内容:
AA:BB:cc:DD
AB:BB:cc:123
AB:BB:cc:DD:hello
ABA:BB:cc:DD:hh
AB:BB:cc:DD
运行结果:
123
hello
DD
如下:
F3 1>N1
Init SMART Fail
LED:000000CC FAddr:0024E4A3
LED:000000CC FAddr:0024E4A3
LED:000000CC FAddr:0024E4A3
LED:000000CC FAddr:0024E4A3
最终此问题已解决!
欢迎分享,转载请注明来源:品搜搜测评网