在方法之间传递值
我有将值读入变量的方法
public void displayFromExcel(String xlsPath) {
.
.
.
pole[i] = cell.getNumericCellValue();
.
.
pole1[j] = richTextString;
然后我有使用 StringBuilder
构建 String
的方法
private void getHenkValues (StringBuilder sb) {
sb.append("<ColumnValue name=\"hen_allockey\">" + pole1[j] + "</ColumnValue\">\r\n"
+"<ColumnValue name=\"hen_percentage\">"+ pole[i] + "</ColumnValue\">\r\n");
}
然后我有将其写入文件的方法:
protected void jobRun() throws Exception {
sb = new StringBuilder();
getHenkValues(sb);
String epilog1 = sb.toString();
FileOutputStream fos = new FileOutputStream("c:\\test\\osem.xml");
OutputStreamWriter osw = new OutputStreamWriter(fos, Charset.forName("UTF-8"));
osw.write(epilog1);
osw.flush();
osw.close();
}
在方法中main
我调用方法jobrun
。
如何从方法 displayFromExcel
到方法 getHenkValues
获取 pole[i]
、pole1[j]
的值?
I've got method where I read value into variable
public void displayFromExcel(String xlsPath) {
.
.
.
pole[i] = cell.getNumericCellValue();
.
.
pole1[j] = richTextString;
Then I have method where I build a String
using StringBuilder
private void getHenkValues (StringBuilder sb) {
sb.append("<ColumnValue name=\"hen_allockey\">" + pole1[j] + "</ColumnValue\">\r\n"
+"<ColumnValue name=\"hen_percentage\">"+ pole[i] + "</ColumnValue\">\r\n");
}
Then I have method where I write it into file:
protected void jobRun() throws Exception {
sb = new StringBuilder();
getHenkValues(sb);
String epilog1 = sb.toString();
FileOutputStream fos = new FileOutputStream("c:\\test\\osem.xml");
OutputStreamWriter osw = new OutputStreamWriter(fos, Charset.forName("UTF-8"));
osw.write(epilog1);
osw.flush();
osw.close();
}
And in method main
I call the method jobrun
.
How can I get the values from pole[i]
, pole1[j]
from method displayFromExcel
to method getHenkValues
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
displayFromExcel
方法需要返回它们(使用自定义类或某种类型的集合,可能是数组)。您的 getHenkValues 也需要接受这些值,您可以尝试以下操作:
或与您的情况相关的任何内容。
Your
displayFromExcel
method need to return them (using a custom class or a collection of some sort, perhaps an array).Your
getHenkValues
needs to accept these values as well, you could try something like:or whatever is relevant for your case.
您可以将polo 和pole1 设置为displayFromExcel、getHenkValues 和jobRun 所在类的私有字段:
然后您可以在一种方法中为这些数组赋值,并在另一种方法中访问它们。
You could make pole and pole1 private fields of the class in which displayFromExcel, getHenkValues and jobRun are located:
Then you can assign values to these arrays in one method and access them in another.