用java读取文本文件
2012-09-12 10:33:50 来源:WEB开发网核心提示:13003000000-13003009999-合肥13003010000-13003029999-蚌埠13003030000-13003049999-芜湖13003050000-13003069999-合肥13003070000-13003079999-淮南13003080000-13003089999-合肥1300
13003000000-13003009999-合肥 13003010000-13003029999-蚌埠 13003030000-13003049999-芜湖 13003050000-13003069999-合肥 13003070000-13003079999-淮南 13003080000-13003089999-合肥 13003090000-13003099999-巢湖 13004000000-13004009999-淮南 13004010000-13004039999-阜阳 13004040000-13004069999-芜湖 13004070000-13004099999-蚌埠 13010300000-13010309999-合肥 13013000000-13013029999-滁州 13013030000-13013039999-巢湖 13013040000-13013049999-池州 13013050000-13013059999-淮南 13013060000-13013099999-合肥 13013100000-13013119999-马鞍山 13013120000-13013129999-黄山 13013130000-13013149999-宣城 13013150000-13013159999-铜陵 13013160000-13013199999-安庆 13014000000-13014019999-宿州 13014020000-13014039999-六安 13014040000-13014059999-淮北 13014060000-13014099999-阜阳 13023000000-13023009999-合肥 13023010000-13023029999-蚌埠 13023030000-13023049999-芜湖
开始读取:java源文件:ShowTel.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/手机号码归属地/安徽联通.txt"); BufferedReader br = new BufferedReader(fr); String str = null; String[] arr = null; System.out.println("开始号码\t结束号码\t归属地"); while((str = br.readLine())!= null ){ arr = str.split("-"); System.out.println(arr[0]+"\t"+arr[1]+"\t"+arr[2]); } } }
运行截图如下:
3、主要知识点:
1)readLine():逐行读取 2)spilt():分割字符串为字符串数组 3)FileReader和BufferedReader的使用
更多精彩
赞助商链接