3

我有 Element 类的数据。我正在尝试将其值写入文件,但我遇到了麻烦:

< 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
4

4 回答 4

5

事实证明,这个 Bloomberg Prop 数据结构至少可以说是冗长的:

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); 

/* the above codes were known at the time of the question */
/* below is what I was shown by a bloomberg representative */

Element bulkElement = field.getValueAsElement(0);
Element elem = bulkElement.getElement(0);
out.write(elem.name() + "\t" + elem.getValueAsString() + "\n");

哇...我不认为他们试图让它变得容易!我也很好奇是否有一种方法可以通过让 Java 打印出正确的方法来追踪数据结构来解决这个问题?

于 2010-09-02T15:32:03.980 回答
1
 Element element = msg.GetElement("securityData");
 for (int i = 0; i < element.NumValues; i++)
 {

  Element security = element.GetValueAsElement(i);  //ie: DJI INDEX
  Element fields = security.GetElement("fieldData");//ie: INDX_MEMBERS

  for (int j = 0; j < fields.NumElements; j++) 
  {
   Element field = fields.GetElement(j); //a list of members

   for (int k = 0; k < field.NumValues; k++)
   {
       //print field.GetValueAsElement(k); //print members name              
   } 
  }

 }
于 2012-11-28T05:30:15.020 回答
0

听起来您正在尝试打印输入字段元素的值?

如果是这样,请尝试:

out.write(field.getAttribute("value"));
于 2010-09-01T21:20:49.110 回答
0

看看这个,你的第二个问题:http: //download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html

于 2010-09-01T21:26:17.020 回答