這裏描述了ADIF格式:http://www.adif.org/我正在嘗試製作Adif解析器。下面是ADIF文件的部分解析:Java解析ADIF文件
ADIF 2 Export from eQSL.cc
Received eQSLs for IZ1080SWL
for QSOs between 10-Aug-2015 and 31-Dec-2035
Generated on Sunday, October 18, 2015 at 00:48:50 AM UTC
<PROGRAMID:21>eQSL.cc DownloadInBox
<ADIF_Ver:1>2
<EOH>
<CALL:6>RA1QEA<QSO_DATE:8:D>20150829<TIME_ON:4>0455<BAND:3>30m<MODE:2>CW<RST_SENT:3>SWL<RST_RCVD:0><QSL_SENT:1>Y<QSL_SENT_VIA:1>E<APP_EQSL_AG:1>Y<GRIDSQUARE:6>lo19aq<EOR>
<CALL:5>F6HKA<QSO_DATE:8:D>20150910<TIME_ON:4>0400<BAND:3>80m<MODE:2>CW<RST_SENT:3>swl<RST_RCVD:0><QSL_SENT:1>Y<QSL_SENT_VIA:1>E<QSLMSG:34>Thanks for the SWL report. 73 Bert<APP_EQSL_AG:1>Y<GRIDSQUARE:6>JN05ot<EOR>
<CALL:5>DL5ZL<QSO_DATE:8:D>20150912<TIME_ON:4>2229<BAND:3>30m<MODE:2>CW<RST_SENT:3>599<RST_RCVD:0><QSL_SENT:1>Y<QSL_SENT_VIA:1>E<QSLMSG:28>tks, paper qsl is on the way<APP_EQSL_AG:1>Y<GRIDSQUARE:6>JO51jl<EOR>
<CALL:5>4Z5ML<QSO_DATE:8:D>20150915<TIME_ON:4>0504<BAND:3>20m<MODE:2>CW<RST_SENT:3>599<RST_RCVD:0><QSL_SENT:1>Y<QSL_SENT_VIA:1>E<APP_EQSL_AG:1>Y<GRIDSQUARE:4>km72<EOR>
我試試這個解析器:
public void read() throws IOException {
BufferedReader br = new BufferedReader(new FileReader(filePath));
int intValue;
boolean createToken = false;
boolean createSize = false;
StringBuffer token = new StringBuffer();
StringBuffer size = new StringBuffer();
Adif2Record record = new Adif2Record();
while ((intValue = br.read()) != -1) {
char cValue = (char)intValue;
if (cValue == '\n') {
continue;
}
if (cValue == '<') {
createToken = true;
continue;
}
if (cValue == ':') {
createToken = false;
createSize = true;
continue;
}
if (cValue == '>') {
if ("eor".equalsIgnoreCase(token.toString())) {
records.add(record);
record = new Adif2Record();
token.setLength(0);
size.setLength(0);
continue;
}
createSize = false;
createData(br, token.toString(), str2int(size.toString()), record);
size.setLength(0);
token.setLength(0);
}
if (createToken) {
token.append(cValue);
}
if (createSize) {
size.append(cValue);
}
}
}
,但我最終只能用一個令牌「PROGRAMID」和文件的其餘部分用於此令牌成爲數據。 EOF標記之前的部分是一個標題,我不想完全切斷它,但我不明白爲什麼createSize在PROGRAMID後保持爲真,根據想法它應該在每個循環後重置爲false。有人可以幫忙嗎?
'如果(cValue == '一'){}如果(cValue == 'B'){ } if(cValue =='c'){}'看起來像你可以把這個更可讀性寫成'switch(cValue){case'a':case'b':case'c':}' – fabian