äºå®ä¸æä¸ç¥éåªä¸è¡æ¯bb,æ以tmp[1]ä¸è¡å§
追çFile file = new File("E:\\bb.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while((line = br.readLine())!= null){ //ä¸æ¬¡è¯»åä¸è¡
System.out.println(line);
String[] tmp = line.split("---"); //æ ¹æ®--å°æ¯è¡æ°æ®æåæä¸ä¸ªæ°ç»
for(int i=0; i<tmp.length; i++){
System.out.println("\t" + tmp[i]); //tmp[1]å°±æ¯ä½ æ³è¦çbb
}
if(line.endsWith("bb")){
//å¤ææ¬è¡æ¯å¦ä»¥bbç»æ
System.out.println("è¿æ¯ææ³è¦ç: " + tmp[1]);
}
}
br.close();
public static String readFile(String filepath) {
StringBuffer string=new StringBuffer();
BufferedReader br=null;
try {
InputStreamReader isr = new InputStreamReader(new FileInputStream(filepath));
br=new BufferedReader(isr);
String line = null;
while((line=br.readLine())!= null){
string.append(line);
string.append("\n");
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return string.toString();
}
public static String rightStr(String str, int count) {
String result = "";
if (!strIsNull(str)) {
if (str.length() > count) {
result = str.substring(str.length() - count);
} else {
result = str;
}
}
return result;
}