gpt4 book ai didi

java - 如何使用java导出文件?

转载 作者:行者123 更新时间:2023-12-01 05:06:27 25 4
gpt4 key购买 nike

我正在尝试使用以下代码导出提要文件:

String appname = "abc";
String path = "//home/exportfile//";
String filename = path + "Uncorrelated_ApplicationExport-" + appname + ".txt";
String ret = "false";

QueryOptions ops = new QueryOptions();
Filter[] filters = new Filter[1];
filters[0] = Filter.eq("application.name", appname);
ops.add(filters);

List props = new ArrayList();
props.add("identity.name");

// Do search
Iterator it = context.search(Link.class, ops, props);

// Build file and export header row
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write("Userid~First_Name~Last_Name~Facility/CBO~Title~Menu");
out.newLine();

// Iterate Search Results
if (it != null)
{
while (it.hasNext())
{
// Get link and create object
Object[] record = it.next();
String identityName = (String) record[0];
Identity user = (Identity) context.getObject(Identity.class, identityName);

// Get Identity attributes for export
String workforceid = (String) user.getAttribute("workforceID");

// Get application attributes for export

List links = user.getLinks();
if (links != null)
{
Iterator lit = links.iterator();
while (lit.hasNext())
{
Link l = lit.next();
String lname = l.getApplicationName();
if (lname.equalsIgnoreCase(appname))
{
if (workforceid == null)
{
userid = (String) l.getAttribute("Userid");
fn = (String) l.getAttribute("First Name");
ln = (String) l.getAttribute("Last Name");
menu = (String) l.getAttribute("Menu");

List fac = l.getAttribute("Facility/CBO");
List title = l.getAttribute("Title");

for (Object fac1 : fac)
{
for (Object title1 : title)
{
// Output file

out
.write(userid + "~" + fn + "~" + ln + "~" + fac1 + "~" + title1 + "~"
+ menu);
out.newLine();
out.flush();

}
}
}
}
}
}
}

ret = "true";
}
// Close file and return
out.close();
return ret;

当我执行上述代码时,出现以下错误:

An unexpected error occurred: java.lang.Exception: sailpoint.tools.GeneralException: BeanShell script error: Sourced file: inline evaluation of: import java.io.FileWriter; import java.io.File; import java.io.B . . . '' : The collection, array, map, iterator, or enumeration portion of a for statement cannot be null. : at Line: 80 : in file: inline evaluation of: ``import java.io.FileWriter; import java.io.File; import java.io.B . . . '' : for ( Object title1 : title ) { BSF info:

我知道在我的提要文件中,标题列中有几个空白记录,因此理想情况下,代码应该将除标题列(如果为空)之外的所有内容写入文件中。任何人都可以帮助我在哪里更改代码吗?

最佳答案

                    List fac = l.getAttribute("Facility/CBO");
List title = l.getAttribute("Title");

for (Object fac1 : fac)
{
for (Object title1 : title)

fac 或 title 被设置为 null,然后您尝试对其进行迭代。您应该在执行循环之前引入一些空检查。

关于java - 如何使用java导出文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12589371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com