package readAndWrite;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class ReadWrite {
public static void main(String[] args) throws IOException {
File writename = new File("/Users/yp-tc-m-4841/Downloads/result.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件
writename.createNewFile(); // 创建新文件
BufferedWriter out = new BufferedWriter(new FileWriter(writename));
File writename1 = new File("/Users/yp-tc-m-4841/Downloads/resultkey.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件
writename.createNewFile(); // 创建新文件
BufferedWriter out1 = new BufferedWriter(new FileWriter(writename1));
File file = new File("/Users/yp-tc-m-4841/Downloads/findTelList.txt");
InputStreamReader reader = new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader = new BufferedReader(reader);
String line = "";
line = bufferedReader.readLine();
StringBuffer sb = new StringBuffer();
while(line != null) {
line = line.trim();
for(int i = line.length();;i--) {
if(istrue(line.substring(i-1, i))) {
sb.append(line.substring(i-1, i));
}else {
break;
}
}
System.out.println(sb.toString());
String str = sb.reverse().toString();
if(!"".equals(str)) {
line = line.substring(0, line.lastIndexOf(str));
}
out1.write(line+"\r\n");
out.write(str+"\r\n");
sb = new StringBuffer();
line = "";
line = bufferedReader.readLine();
}
System.out.println("over...");
reader.close();
out.close();
out1.close();
}
public static boolean istrue(String str) {
str = str.trim();
return "0".equals(str)||"1".equals(str)||"2".equals(str)||"3".equals(str)||"4".equals(str)||"5".equals(str)||
"6".equals(str)||"7".equals(str)||"8".equals(str)||"9".equals(str)||"-".equals(str)||"—".equals(str);
}
}