2012-07-31 78 views
1

我需要導出3列中的4個column.values值正確填充。 我有第四欄是組織column.it是多值column.i.e .:它有多個值的問題。如何使用java導出文件中的數據

我試圖從組織列轉換爲字符串,但沒有幫助。

請參閱下面的代碼:

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("Name,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=""; 

        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"); 
               List orgList = 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; 

這段代碼的輸出應該是:

爲前: 名,用戶名,WorkforceID,組織 ABC,ABC,123,XY QWE ,q01,234,xy

任何幫助糾正此代碼將不勝感激。

回答

1

編輯:

這應該給你輸出你想要的:

out.write(identityName + 「 」+用戶ID +「, 」+ workforceid +「,」 + Arrays.toString(orgList.toArray());

+0

你能指導我在哪裏放這個語法? – user1565893 2012-08-01 13:34:13

+0

你有這樣一行:'out.write(identityName +「,」+ userid +「,」+ workforceid +「,」+ org);'將數據保存到文件中。我在上面的示例代碼中找不到'org'變量。 'org'應該是包含'orgList'數據的字符串嗎? – 2012-08-02 15:37:43

+0

out.write(identityName +「,」+ userid +「,」+ workforceid +「,」+ org); 這裏我改爲orgList,但我仍然得到空值... 如何使用列表函數,並看看是否有toString方法... 因爲組織列中的數據是列表 – user1565893 2012-08-02 18:40:14

0

你可能想,因爲每次被創建它宣佈List orgList while循環之外,也使用的是組織,我還沒有在你的代碼的其他地方看到任何組織

+0

我已在申報名單outsi去while循環並將org更改爲orgList.but仍然沒有幫助讓我獲得組織的輸出。 – user1565893 2012-08-01 13:33:28

相關問題