代码未在文件中写入值 [英] Code is not writing the values in File

查看:23
本文介绍了代码未在文件中写入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导出文件.

我的代码如下:

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 列的值.不知道为什么?

Code is writing the value for 3 columns except Organization column. Not sure why?

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

Can you pls help me to identify what is wrong with the code. Or what i am missing.

顺便说一下,Organization 列是多值的,即该列可能有多个值.

By the way, Organization column is multivalue i.e. that column might have more than one value.

所以最终输出应该是,

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

任何帮助将不胜感激.

推荐答案

String org="";是空的.您似乎没有将值分配给 org,因此正在将空值写入文件.

String org=""; is empty. It seems no where you assigned value to org, so empty value is being written to file.

这篇关于代码未在文件中写入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆