Requirement: use java to read the home location file of the mobile phone number
1、 .txt: content:
[Plain] view plaincopyprint?
13003000000-13003009999-Hefei
130030316-13003029999-Bengbu
13003030000-13003049999-Wuhu
13003050000-13003069999-Hefei
13003070000-13003079999-Huainan
13003080000-13003089999-Hefei
13003090000-13003099999-Chaohu
13004000000-13004009999-Huainan
130040316-13004039999-Fuyang
13004040000-13004069999-Wuhu
13004070000-13004099999-Bengbu
13010300000-13010309999-Hefei
1301300316-13013029999-Chuzhou
13013030000-13013039999-Chaohu
13013040000-13013049999-Chizhou
13013050000-13013059999-Huainan
13013060000-13013099999-Hefei
13013100000-13013119999-ma'anshan
13013120000-13013129999-Huangshan
13013130000-13013149999-xuancheng
1301315316-13013159999-Tongling
1301316316-13013%99-Anqing
130141000000-1301409709-Suzhou
13014020000-13014039999-lu'an
13014040000-13014059999-Huaibei
13014060000-13014099999-Fuyang
13023000000-13023009999-Hefei
1302300000-13023029999-Bengbu
13023030000-13023049999-Wuhu
2. Start reading: java source file: ShowTel. java
[Java]
Package com. insigma. zd. group4.liuchao. languagebase;
Import java. io. BufferedReader;
Import java. io. FileReader;
Public class ShowTel {
/**
* @ Param args
*/
Public static void main (String [] args) throws Exception {
// TODO Auto-generated method stub
FileReader fr = new FileReader ("D:/My Documents/mobile phone number/.txt ");
BufferedReader br = new BufferedReader (fr );
String str = null;
String [] arr = null;
System. out. println ("START number \ t end number \ t ");
While (str = br. readLine ())! = Null ){
Arr = str. split ("-");
System. out. println (arr [0] + "\ t" + arr [1] + "\ t" + arr [2]);
}
}
}
Run the following command:
3. Main knowledge points:
1) readLine (): Read row by row 2) spilt (): Split the string into a string array 3) Use of FileReader and BufferedReader
4. Read files to the database.