解析CVS文件括授,存入數(shù)據(jù)庫

直接解析,然后拆分,存到集合里面荚虚,最后保存

// 解析CVS
    public List<CmLteCel> readText(String path) {
        List<CmLteCel> cmltecelList = new ArrayList<CmLteCel>();
        try {
            File file = new File(path);
            System.out.println(path);
            System.out.println(file);
            if (file.isFile() && file.exists()) { // 判斷文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new GZIPInputStream(new FileInputStream(file)), "gbk");// 考慮到編碼格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                int i = 0;
                int j = 0;
                SimpleDateFormat sdf = new SimpleDateFormat(
                        "yyyy-MM-dd hh:mm:ss");
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    if (i++ == 0)
                        continue;
                    String[] s = lineTxt.split("\\|");
                    j = s.length;
                    if (j != 63) {
                        continue;
                    }
                    if (!s[40].equals("440100"))
                        continue;
                    CmLteCel cmltecel = new CmLteCel();
                    cmltecel.setCreateDate(null);
                    cmltecel.setModifyDate(new Date());
                    cmltecel.setAntCode(s[0]);
                    cmltecel.setAntIntId(s[1]);
                    cmltecel.setAntZoType(StringUtils.trim(s[2]) != ""
                            && StringUtils.trim(s[2]) != null
                            && !"null".equals(StringUtils.trim(s[2])) ? Long
                            .parseLong(StringUtils.trim(s[2])) : null);
                    cmltecel.setArea1(s[3]);
                    cmltecel.setArea2(s[4]);
                    cmltecel.setArea3(s[5]);
                    cmltecel.setArea4(s[6]);
                    cmltecel.setArea5(s[7]);
                    cmltecel.setBandindicator(StringUtils.trim(s[8]) != ""
                            && StringUtils.trim(s[8]) != null
                            && !"null".equals(StringUtils.trim(s[8])) ? Long
                            .parseLong(StringUtils.trim(s[8])) : null);
                    cmltecel.setBandwidthDl(StringUtils.trim(s[9]) != ""
                            && StringUtils.trim(s[9]) != null
                            && !"null".equals(StringUtils.trim(s[9])) ? Long
                            .parseLong(StringUtils.trim(s[9])) : null);
                    cmltecel.setBandwidthUl(StringUtils.trim(s[10]) != ""
                            && StringUtils.trim(s[10]) != null
                            && !"null".equals(StringUtils.trim(s[10])) ? Long
                            .parseLong(StringUtils.trim(s[10])) : null);
                    cmltecel.setCelCode(s[11]);
                    cmltecel.setCelGrade(StringUtils.trim(s[12]) != ""
                            && StringUtils.trim(s[12]) != null
                            && !"null".equals(StringUtils.trim(s[12])) ? Long
                            .parseLong(StringUtils.trim(s[12])) : null);
                    cmltecel.setCelId(StringUtils.trim(s[13]) != ""
                            && StringUtils.trim(s[13]) != null
                            && !"null".equals(StringUtils.trim(s[13])) ? Long
                            .parseLong(StringUtils.trim(s[13])) : null);
                    cmltecel.setCelIdLocal(StringUtils.trim(s[14]) != ""
                            && StringUtils.trim(s[14]) != null
                            && !"null".equals(StringUtils.trim(s[14])) ? Long
                            .parseLong(StringUtils.trim(s[14])) : null);
                    cmltecel.setCelOptstate(StringUtils.trim(s[15]) != ""
                            && StringUtils.trim(s[15]) != null
                            && !"null".equals(StringUtils.trim(s[15])) ? Long
                            .parseLong(StringUtils.trim(s[15])) : null);
                    cmltecel.setCityId(StringUtils.trim(s[16]) != ""
                            && StringUtils.trim(s[16]) != null
                            && !"null".equals(StringUtils.trim(s[16])) ? Long
                            .parseLong(StringUtils.trim(s[16])) : null);
                    cmltecel.setCityName(s[17]);
                    cmltecel.setColStatus(StringUtils.trim(s[18]) != ""
                            && StringUtils.trim(s[18]) != null
                            && !"null".equals(StringUtils.trim(s[18])) ? Long
                            .parseLong(StringUtils.trim(s[18])) : null);
                    cmltecel.setCoverType(StringUtils.trim(s[19]) != ""
                            && StringUtils.trim(s[19]) != null
                            && !"null".equals(StringUtils.trim(s[19])) ? Long
                            .parseLong(StringUtils.trim(s[19])) : null);
                    cmltecel.setCutCoverFlag(StringUtils.trim(s[20]) != ""
                            && StringUtils.trim(s[20]) != null
                            && !"null".equals(StringUtils.trim(s[20])) ? Long
                            .parseLong(StringUtils.trim(s[20])) : null);
                    cmltecel.setDataTime(StringUtils.trim(s[21]) != ""
                            && StringUtils.trim(s[21]) != null
                            && !"null".equals(StringUtils.trim(s[21])) ? sdf
                            .parse(StringUtils.trim(s[21])) : null);
                    cmltecel.setEci(s[22]);
                    cmltecel.setFreqDl(s[23]);
                    cmltecel.setFreqMode(StringUtils.trim(s[24]) != ""
                            && StringUtils.trim(s[24]) != null
                            && !"null".equals(StringUtils.trim(s[24])) ? Long
                            .parseLong(StringUtils.trim(s[24])) : null);
                    cmltecel.setFreqPointnoDl(StringUtils.trim(s[25]) != ""
                            && StringUtils.trim(s[25]) != null
                            && !"null".equals(StringUtils.trim(s[25])) ? Long
                            .parseLong(StringUtils.trim(s[25])) : null);
                    cmltecel.setFreqPointnoUl(StringUtils.trim(s[26]) != ""
                            && StringUtils.trim(s[26]) != null
                            && !"null".equals(StringUtils.trim(s[26])) ? Long
                            .parseLong(StringUtils.trim(s[26])) : null);
                    cmltecel.setFreqUl(s[27]);
                    cmltecel.setIntId(StringUtils.trim(s[28]) != ""
                            && StringUtils.trim(s[28]) != null
                            && !"null".equals(StringUtils.trim(s[28])) ? Long
                            .parseLong(StringUtils.trim(s[28])) : null);
                    cmltecel.setIsShareAnt(StringUtils.trim(s[29]) != ""
                            && StringUtils.trim(s[29]) != null
                            && !"null".equals(StringUtils.trim(s[29])) ? Long
                            .parseLong(StringUtils.trim(s[29])) : null);
                    cmltecel.setMeid(StringUtils.trim(s[30]) != ""
                            && StringUtils.trim(s[30]) != null
                            && !"null".equals(StringUtils.trim(s[30])) ? Long
                            .parseLong(StringUtils.trim(s[30])) : null);
                    cmltecel.setMissTimes(StringUtils.trim(s[31]) != ""
                            && StringUtils.trim(s[31]) != null
                            && !"null".equals(StringUtils.trim(s[31])) ? Long
                            .parseLong(StringUtils.trim(s[31])) : null);
                    cmltecel.setMultiAntType(StringUtils.trim(s[32]) != ""
                            && StringUtils.trim(s[32]) != null
                            && !"null".equals(StringUtils.trim(s[32])) ? Long
                            .parseLong(StringUtils.trim(s[32])) : null);
                    cmltecel.setNetworkStatus(StringUtils.trim(s[33]) != ""
                            && StringUtils.trim(s[33]) != null
                            && !"null".equals(StringUtils.trim(s[33])) ? Long
                            .parseLong(StringUtils.trim(s[33])) : null);
                    cmltecel.setObjectRdn(s[34]);
                    cmltecel.setOmcId(StringUtils.trim(s[35]) != ""
                            && StringUtils.trim(s[35]) != null
                            && !"null".equals(StringUtils.trim(s[35])) ? Long
                            .parseLong(StringUtils.trim(s[35])) : null);
                    cmltecel.setPci(StringUtils.trim(s[36]) != ""
                            && StringUtils.trim(s[36]) != null
                            && !"null".equals(StringUtils.trim(s[36])) ? Long
                            .parseLong(StringUtils.trim(s[36])) : null);
                    cmltecel.setProvinceId(StringUtils.trim(s[37]) != ""
                            && StringUtils.trim(s[37]) != null
                            && !"null".equals(StringUtils.trim(s[37])) ? Long
                            .parseLong(StringUtils.trim(s[37])) : null);
                    cmltecel.setProvinceName(s[38]);
                    cmltecel.setRecStatus(StringUtils.trim(s[39]) != ""
                            && StringUtils.trim(s[39]) != null
                            && !"null".equals(StringUtils.trim(s[39])) ? Long
                            .parseLong(StringUtils.trim(s[39])) : null);
                    cmltecel.setRegionId(StringUtils.trim(s[40]) != ""
                            && StringUtils.trim(s[40]) != null
                            && !"null".equals(StringUtils.trim(s[40])) ? Long
                            .parseLong(StringUtils.trim(s[40])) : null);
                    cmltecel.setRegionName(s[41]);
                    cmltecel.setRelatedEnbId(StringUtils.trim(s[42]) != ""
                            && StringUtils.trim(s[42]) != null
                            && !"null".equals(StringUtils.trim(s[42])) ? Long
                            .parseLong(StringUtils.trim(s[42])) : null);
                    cmltecel.setRelatedEnbIntId(StringUtils.trim(s[43]) != ""
                            && StringUtils.trim(s[43]) != null
                            && !"null".equals(StringUtils.trim(s[43])) ? Long
                            .parseLong(StringUtils.trim(s[43])) : null);
                    cmltecel.setRelatedEnbUserlabel(s[44]);
                    cmltecel.setRemark(s[45]);
                    cmltecel.setRoomCode(s[46]);
                    cmltecel.setRoomIntId(s[47]);
                    cmltecel.setRruCode(s[48]);
                    cmltecel.setRruIntId(s[49]);
                    cmltecel.setSubnetwork(StringUtils.trim(s[50]) != ""
                            && StringUtils.trim(s[50]) != null
                            && !"null".equals(StringUtils.trim(s[50])) ? Long
                            .parseLong(StringUtils.trim(s[50])) : null);
                    cmltecel.setTac(StringUtils.trim(s[51]) != ""
                            && StringUtils.trim(s[51]) != null
                            && !"null".equals(StringUtils.trim(s[51])) ? Long
                            .parseLong(StringUtils.trim(s[51])) : null);
                    cmltecel.setTdSfassignment(s[52]);
                    cmltecel.setTdSpecialsfpatterns(s[53]);
                    cmltecel.setTownName(s[54]);
                    cmltecel.setUpdateTime(StringUtils.trim(s[55]) != ""
                            && StringUtils.trim(s[55]) != null
                            && !"null".equals(StringUtils.trim(s[55])) ? sdf
                            .parse(StringUtils.trim(s[55])) : null);
                    cmltecel.setUpdateTimeSys(StringUtils.trim(s[56]) != ""
                            && StringUtils.trim(s[56]) != null
                            && !"null".equals(StringUtils.trim(s[56])) ? sdf
                            .parse(StringUtils.trim(s[56])) : null);
                    cmltecel.setUpdateUser(s[57]);
                    cmltecel.setUpdateUserid(s[58]);
                    cmltecel.setUserlabel(s[59]);
                    cmltecel.setVendorId(StringUtils.trim(s[60]) != ""
                            && StringUtils.trim(s[60]) != null
                            && !"null".equals(StringUtils.trim(s[60])) ? Long
                            .parseLong(StringUtils.trim(s[60])) : null);
                    cmltecel.setVendorName(s[61]);
                    cmltecel.setZcIdx(StringUtils.trim(s[62]) != ""
                            && StringUtils.trim(s[62]) != null
                            && !"null".equals(StringUtils.trim(s[62])) ? Long
                            .parseLong(StringUtils.trim(s[62])) : null);
                    cmltecelList.add(cmltecel);
                }
                read.close();
            } else {
                System.out.println("找不到指定的文件");
            }

        } catch (Exception e) {
            System.out.println("讀取文件內(nèi)容出錯");
            cmltecelList = null;
            e.printStackTrace();
            return cmltecelList;
        }
        return cmltecelList;
    }
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末薛夜,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子曲管,更是在濱河造成了極大的恐慌却邓,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件院水,死亡現(xiàn)場離奇詭異腊徙,居然都是意外死亡,警方通過查閱死者的電腦和手機檬某,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進店門撬腾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人恢恼,你說我怎么就攤上這事民傻。” “怎么了场斑?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵漓踢,是天一觀的道長。 經(jīng)常有香客問我漏隐,道長喧半,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任青责,我火速辦了婚禮挺据,結果婚禮上,老公的妹妹穿的比我還像新娘脖隶。我一直安慰自己扁耐,他們只是感情好,可當我...
    茶點故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布产阱。 她就那樣靜靜地躺著婉称,像睡著了一般。 火紅的嫁衣襯著肌膚如雪构蹬。 梳的紋絲不亂的頭發(fā)上酿矢,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天,我揣著相機與錄音怎燥,去河邊找鬼。 笑死蜜暑,一個胖子當著我的面吹牛铐姚,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼隐绵,長吁一口氣:“原來是場噩夢啊……” “哼之众!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起依许,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤棺禾,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后峭跳,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體膘婶,經(jīng)...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年蛀醉,在試婚紗的時候發(fā)現(xiàn)自己被綠了悬襟。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,117評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡拯刁,死狀恐怖脊岳,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情垛玻,我是刑警寧澤割捅,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站帚桩,受9級特大地震影響亿驾,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜朗儒,卻給世界環(huán)境...
    茶點故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一颊乘、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧醉锄,春花似錦乏悄、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至烟勋,卻和暖如春规求,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背卵惦。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工阻肿, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人沮尿。 一個月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓丛塌,卻偏偏與公主長得像较解,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子赴邻,可洞房花燭夜當晚...
    茶點故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內(nèi)容