BufferedReader读取次数过多

时间:2014-02-11 12:58:53

标签: java bufferedreader

我无法理解因为这段代码读了太多次文件。使用带有特殊字符作为分隔符的CSV的相同代码效果很好......但是带有CSV;因为分隔符读取同一文件的次数太多了。

这是cose:

public static ArrayList<Asset> retriveCIInstances(File sap_csv_source, String parseChar) throws IOException {
    System.out.println("PARSING WITH THE CHAR: " + parseChar);
    ArrayList<Asset> res = new ArrayList<Asset>();      
    FileInputStream fstream = new FileInputStream(sap_csv_source);        
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine; 
    while ((strLine = br.readLine()) != null)   {
        System.out.println("LINE CSV: " + strLine);
        String[] raw = strLine.split(parseChar);
        res.add(new Asset(null,raw[1],raw[0],raw[8], null,null));
    }
    in.close();
    fstream.close();
    return res;
}

并且两个文件的内容是: (不起作用)

ASSET_TAG;SAP Purchase Order number;SAP Purchase Order position number;Asset Type;Asset Category;Asset description;Manufacturer;Model;Serial Number;Location ID;Delivery Note number;Delivery note date;EOF
B1CSSW01SN78JJNYU76U;4500136741;20;Switch;Network;;Cisco;WS-C2960-24LT-L;SN78JJNYU76U;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
B1CSSW01SNRU7687JUIUJ;4500136741;20;Switch;Network;;Cisco;WS-C2960-24LT-L;SNRU7687JUIUJ;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
B1CSSW01SNFGH6765Y66;4500136741;20;Switch;Network;;Cisco;WS-C2960-24LT-L;SNFGH6765Y66;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
B1CSSW01SN3435REG45Y;4500136741;20;Switch;Network;;Cisco;WS-C2960-24LT-L;SN3435REG45Y;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF

或 (作品)

 ASSET_TAG¤SAP Purchase Order number¤SAP Purchase Order position number¤Asset Type¤Asset Category¤Asset description¤Manufacturer¤Model¤Serial Number¤Location ID¤Delivery Note number¤Delivery note date¤EOF
B1HPDT06SN345TREG5Y¤4500117819¤10¤Desktop¤Workstation¤¤HP¤8200 Elite SFF Standard¤SN345TREG5Y¤X-RM-0047_04¤TEST_HW00_11FEB14|17|4500117819-10¤11/02/2014¤EOF
B1HPDT06SN56654GHTD¤4500117819¤10¤Desktop¤Workstation¤¤HP¤8200 Elite SFF Standard¤SN56654GHTD¤X-RM-0047_04¤TEST_HW00_11FEB14|17|4500117819-10¤11/02/2014¤EOF
B1HPDT06SNGJ987IKJJH¤4500117819¤10¤Desktop¤Workstation¤¤HP¤8200 Elite SFF Standard¤SNGJ987IKJJH¤X-RM-0047_04¤TEST_HW00_11FEB14|17|4500117819-10¤11/02/2014¤EOF
B1HPDT06SN65765HT56¤4500117819¤10¤Desktop¤Workstation¤¤HP¤8200 Elite SFF Standard¤SN65765HT56¤X-RM-0047_04¤TEST_HW00_11FEB14|17|4500117819-10¤11/02/2014¤EOF

输出是:

 LINE CSV: ASSET_TAG;SAP Purchase Order number;SAP Purchase Order position
;Asset Type;Asset Category;Asset description;Manufacturer;Model;Serial Num
cation ID;Delivery Note number;Delivery note date;EOF
LINE CSV: B1CSSW01SN78JJNYU76U;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN78JJNYU76U;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SNRU7687JUIUJ;4500136741;20;Switch;Network;;Cisco;WS-C29
T-L;SNRU7687JUIUJ;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;E
LINE CSV: B1CSSW01SNFGH6765Y66;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SNFGH6765Y66;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SN3435REG45Y;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN3435REG45Y;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: ASSET_TAG;SAP Purchase Order number;SAP Purchase Order position
;Asset Type;Asset Category;Asset description;Manufacturer;Model;Serial Num
cation ID;Delivery Note number;Delivery note date;EOF
LINE CSV: B1CSSW01SN78JJNYU76U;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN78JJNYU76U;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SNRU7687JUIUJ;4500136741;20;Switch;Network;;Cisco;WS-C29
T-L;SNRU7687JUIUJ;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;E
LINE CSV: B1CSSW01SNFGH6765Y66;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SNFGH6765Y66;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SN3435REG45Y;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN3435REG45Y;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: ASSET_TAG;SAP Purchase Order number;SAP Purchase Order position
;Asset Type;Asset Category;Asset description;Manufacturer;Model;Serial Num
cation ID;Delivery Note number;Delivery note date;EOF
LINE CSV: B1CSSW01SN78JJNYU76U;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN78JJNYU76U;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SNRU7687JUIUJ;4500136741;20;Switch;Network;;Cisco;WS-C29
T-L;SNRU7687JUIUJ;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;E
LINE CSV: B1CSSW01SNFGH6765Y66;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SNFGH6765Y66;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SN3435REG45Y;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN3435REG45Y;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: ASSET_TAG;SAP Purchase Order number;SAP Purchase Order position
;Asset Type;Asset Category;Asset description;Manufacturer;Model;Serial Num
cation ID;Delivery Note number;Delivery note date;EOF
LINE CSV: B1CSSW01SN78JJNYU76U;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN78JJNYU76U;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SNRU7687JUIUJ;4500136741;20;Switch;Network;;Cisco;WS-C29
T-L;SNRU7687JUIUJ;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;E
LINE CSV: B1CSSW01SNFGH6765Y66;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SNFGH6765Y66;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF
LINE CSV: B1CSSW01SN3435REG45Y;4500136741;20;Switch;Network;;Cisco;WS-C296
-L;SN3435REG45Y;X-MAG-VIRTUA;TEST11FEB2014|17|4500136741-20;11/02/2014;EOF

四行打印很多行...我不明白。

有什么想法吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

这是一个愚蠢的问题......文件被外部来源多次写入。抱歉给你带来不便!我很羞愧