我有一個Element類的數據。我想它的值寫入一個文件,但我有麻煩:使用java將元素對象寫入文件
< Some process to acquire values into the variable "fieldData" >
// Prepare file output
FileWriter fstream = new FileWriter("C:/output.txt");
BufferedWriter out = new BufferedWriter(fstream);
Element field = fieldData.getElement(i);
out.write(field); // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String
,我應該如何處理這種情況下,有什麼建議?另外,對於我來說,看到(即打印到屏幕上)與對象關聯的可用靜態變量和方法的最佳方式是什麼?謝謝。
更多的代碼片段來幫助調試:
private static final Name SECURITY_DATA = new Name("securityData");
private static final Name FIELD_DATA = new Name("fieldData");
Element securityDataArray = msg.getElement(SECURITY_DATA); // msg is a Bloomberg desktop API object
Element securityData = securityDataArray.getValueAsElement(0);
Element fieldData = securityData.getElement(FIELD_DATA);
Element field = fieldData.getElement(0)
out.write(field); // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String
「getValueAsString」方法的返回類型是什麼?它接縫這個返回不是一個字符串,而是一個SEQUENCE。 – 2010-09-01 21:22:49
如何檢查「退貨類型」? – Zhang18 2010-09-01 21:46:04
基本上,'getValueAsString'方法*不適用於'field'對象(!)而錯誤代碼就是我在評論中顯示的內容。我試圖打印'field.getClass()'並得到'com.bloomberglp.blpapi.impl.aB'這是否意味着它是一個彭博專有類,即使它被稱爲Element,它的行爲不像Java中的泛型Element類? – Zhang18 2010-09-01 21:53:06