我嘗試導出使用下面的代碼Feed文件:如何使用java導出文件?
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:
我知道,在我的飼料文件,標題欄中有幾個空白記錄,所以理想情況下,代碼應該將除標題欄外的所有內容寫入文件中。任何人都可以幫助我在哪裏做代碼更改?