java - 使用 java 将 Element 对象写入文件

标签 java data-structures bloomberg

我有一个 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

最佳答案

事实证明,这个 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 打印出用于追踪数据结构的正确方法来解决这个问题?

关于java - 使用 java 将 Element 对象写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3622225/

相关文章:

java - 如何从 gradle javadoc 任务中排除生成的文件?

c++ - 如何解释 'regex e' 行?

api - 彭博 API 公司行动

bloomberg - 在 Java v3 Bloomberg API 中启动 bbcomm

excel - 更新表后刷新 BDH。布隆伯格。伏巴

java - 如何从元素 : after it's in a div with Selenium? 获取内容

java - 在java正则表达式中获取匹配的模式值

java - 将 GPS 坐标发送到另一部手机

algorithm - 关于 Ukkonen 的后缀树的说明

c# - 在内存中保存大型可编辑文档的最佳方法