我有一段代码来读取ofx文件以检索多个标签(例如帐号,余额等)我正在使用net.sf.ofx4j
一段代码:
public void parse(String filename) throws OFXParseException, IOException, SQLException {
AggregateUnmarshaller<ResponseEnvelope> unmarshaller = new AggregateUnmarshaller<ResponseEnvelope>(
ResponseEnvelope.class);
FileInputStream file = null;
try {
file = new FileInputStream(filename);
ResponseEnvelope envelope = unmarshaller.unmarshal(file);
BankingResponseMessageSet messageSet = (BankingResponseMessageSet) envelope.getMessageSet(MessageSetType.banking);
List<BankStatementResponseTransaction> responses = messageSet.getStatementResponses();
for (BankStatementResponseTransaction response : responses) {
BankStatementResponse message = response.getMessage();
String currencyCode = message.getCurrencyCode();
String acct_number = message.getAccount().getAccountNumber();
double av = message.getAvailableBalance().getAmount();
double cur = message.getLedgerBalance().getAmount();
AccountType acct_type = message.getAccount().getAccountType();
}
} catch (OFXParseException e) {
System.out.println("Error: " + e.getMessage());
}
return null;
}
public void parse(String filename) throws OFXParseException, IOException, SQLException {
AggregateUnmarshaller<ResponseEnvelope> unmarshaller = new AggregateUnmarshaller<ResponseEnvelope>(
ResponseEnvelope.class);
FileInputStream file = null;
try {
file = new FileInputStream(filename);
ResponseEnvelope envelope = unmarshaller.unmarshal(file);
BankingResponseMessageSet messageSet = (BankingResponseMessageSet) envelope.getMessageSet(MessageSetType.banking);
List<BankStatementResponseTransaction> responses = messageSet.getStatementResponses();
for (BankStatementResponseTransaction response : responses) {
BankStatementResponse message = response.getMessage();
String currencyCode = message.getCurrencyCode();
String acct_number = message.getAccount().getAccountNumber();
double av = message.getAvailableBalance().getAmount();
double cur = message.getLedgerBalance().getAmount();
AccountType acct_type = message.getAccount().getAccountType();
}
} catch (OFXParseException e) {
System.out.println("Error: " + e.getMessage());
}
return null;
}
它工作正常,直到有一天它开始抛出以下异常:
net.sf.ofx4j.io.AggregateStackContentHandler onElement 信息:索引70处的聚合SONRS(类net.sf.ofxj.domain.data.signon.SignonResponse)不支持元素INTU.BID。
net.sf.ofx4j.io.AggregateStackContentHandler onElement 信息:索引70处的聚合SONRS(类net.sf.ofxj.domain.data.signon.SignonResponse)不支持元素INTU.USERID。
线程“main”中的异常java.lang.IllegalStateException:java.io.IOException:意外的EOF
由于
答案 0 :(得分:0)
希望ofx文件格式应该改变。因为您要求( MessageSetType 。* 银行 *)。但在您的ofx文件中可能有信用卡详细信息。
早期,交易数据包含在&lt; BANKMSGSRSV1 &gt;内的.ofx文件中。标签。 但现在交易数据包括在&lt; CREDITCARDMSGSRSV &gt;标签。您需要更改数据接收代码。
希望你能从中得到一些帮助。谢谢