在使用Java程序读取.csv文件时,遇到数据读取不全,部分数据丢失的问题。
对传输成功的数据和丢失的数据进行对比:
"1227280156","21-SEP-15 12.55.21.830 PM","11.1.12.132","1","144.28.139.144","106.38.221.238","4587","80","20:16:A3:C4:06:67","00:0D:48:2A:64:D9","","","","6","传统协议","","HTTP","","","","","","","","","","","/crossdomain.xml","GET","0","","","http://static.youku.com/v1.0.0569/v/swf/loader.swf","0","valc.atm.youku.com","","娱乐视频","","",""
"1227280157","21-SEP-15 12.55.21.830 PM","11.1.12.132","1","35.16.151.233","144.28.238.149","51868","80","20:16:A3:B7:DD:5A","00:0D:48:2A:64:D9","","","","6","传统协议","","HTTP","","","","","","","","","","","/swfs/51/2765427637x/gfd8fhd.flv","GET","0","","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)","http://ubmcmm.baidustatic.com/media/v1/0f0007ZXkm5LYjHeqBwkc0.swf","0","kwflvcdn.000dn.com","","","","",""
为了观察方便,进行展开:
"1227280156",
"21-SEP-15 12.55.21.830 PM",
"11.1.12.132",
"1",
"144.28.139.144",
"106.38.221.238",
"4587",
"80",
"20:16:A3:C4:06:67",
"00:0D:48:2A:64:D9",
"",
"",
"",
"6",
"传统协议",
"",
"HTTP",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"/crossdomain.xml",
"GET",
"0",
"",
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36",
"http://static.youku.com/v1.0.0569/v/swf/loader.swf",
"0",
"valc.atm.youku.com",
"",
"娱乐视频",
"",
"",
""
"1227280157",
"21-SEP-15 12.55.21.830 PM",
"11.1.12.132",
"1",
"35.16.151.233",
"144.28.238.149",
"51868",
"80",
"20:16:A3:B7:DD:5A",
"00:0D:48:2A:64:D9",
"",
"",
"",
"6",
"传统协议",
"",
"HTTP",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"/swfs/51/2765427637x/gfd8fhd.flv",
"GET",
"0",
"",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
"http://ubmcmm.baidustatic.com/media/v1/0f0007ZXkm5LYjHeqBwkc0.swf",
"0",
"kwflvcdn.000dn.com",
"",
"",
"",
"",
""
上面那条数据发送失败,下面那条数据发送成功。
然后寻找原因,发送过程中使用到了ine.split(",")对数据进行分割,第一条数据的字段中,也出现有逗号,因此会导致数据分割失败。
对代码进行修改:
String[] str = line.split("\",");
增加过滤的内容,保证数据不被单个逗号影响。
此时,数据发送成功。