gpt4 book ai didi

java - 代码未将值写入文件中

转载 作者:行者123 更新时间:2023-12-01 15:15:01 24 4
gpt4 key购买 nike

我正在尝试导出文件。

我的代码如下:

import java.io.FileWriter;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.*;


String appname = "Abc";
String path = "//home/exportfile//";
String filename = path+"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("IdentityName,UserName,WorkforceID,Organization");
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
String userid="";
String org="";
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))
{
userid = (String) l.getAttribute("User Name");
sailpoint.tools.xml.PersistentArrayList orgList = (sailpoint.tools.xml.PersistentArrayList) l.getAttribute("Organization");

}
}
}

//Output file
out.write(identityName+","+userid+","+workforceid+","+org);
out.newLine();
out.flush();
}
ret="true";
}
//Close file and return
out.close();
return ret;

代码正在写入除“组织”列之外的 3 列的值。不知道为什么?

你能帮我找出代码有什么问题吗?或者我缺少什么。

顺便说一下,组织列是多值的,即该列可能有多个值。

所以最终的输出应该是,

IdentityName,  UserName,  WorkforceID,  Organization 
1, abc, 123, internal
1, abc, 123, external

任何帮助将不胜感激。

最佳答案

字符串组织=“”;是空的。似乎没有为 org 分配值,因此空值被写入文件。

关于java - 代码未将值写入文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11742453/

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