使用 java 将 Element 对象写入文件

发布于 2024-09-16 22:49:59 字数 1257 浏览 4 评论 0原文

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

I have a data of Element class. I'm trying to write its values to a file but I'm having trouble:

< 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

Any suggestions on how I should handle this case? In addition, what is the best way for me to see (i.e. print out to screen) the available static variables and methods associated with an object? Thx.

More code snippets to help debug:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

顾铮苏瑾 2024-09-23 22:49:59

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

Turns out that this Bloomberg Prop data structure is long-winded to say the least:

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

whew...I don't think they try to make it easy! I'm also curious as to if there was a way that I could have figure this out by having Java print out the right method to use to trace down the data structure?

毅然前行 2024-09-23 22:49:59
 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              
   } 
  }

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

 }
眼眸里的那抹悲凉 2024-09-23 22:49:59

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

如果是这样,请尝试:

out.write(field.getAttribute("value"));

It sounds like you are trying to print the value of a input field element?

If so, then try:

out.write(field.getAttribute("value"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文