Help reading .csv file into an arraylist

i need to read a csv file into an arraylist and then print the arraylist to the screen.
using:
try {
            // Setup our scanner to read the file at the path c:\test.txt
            Scanner myscanner = new Scanner(new File("\\carsDB.csv"));    
ArrayList<CarsClass> carsClass = new ArrayList<CarsClass>(" write all fields");   
            while (myscanner.hasNextLine()) {
myscanner.add(" add car fields to the carClass");              // Write your code here.
// loop to read them all to the screencsv file is like this:
Manufacturer,carline name,displ,cyl,fuel,(miles),Class
CHEVROLET,CAVALIER (natural gas),2.2,4,CNG,120,SUBCOMPACT CARS
HONDA,CIVIC GX (natural gas),1.6,4,CNG,190,SUBCOMPACT CARS
FORD,CONTOUR (natural gas),2,4,CNG,70,COMPACT
FORD,CROWN VICTORIA (natural gas),4.6,8,CNG,140/210*,LARGE CARS
FORD,F150 PICKUP (natural gas) - 2WD,5.4,8,CNG,130,STANDARD PICKUP TRUCKS 2WD
FORD,F250 PICKUP (natural gas) - 2WD,5.4,8,CNG,160,STANDARD PICKUP TRUCKS 2WD
FORD,F250 PICKUP (natural gas) - 2WD,5.4,8,CNG,150/210*,STANDARD PICKUP TRUCKS 2WD
FORD,F150 PICKUP (natural gas) - 4WD,5.4,8,CNG,130,STANDARD PICKUP TRUCKS 4WD
FORD,F250 PICKUP (natural gas) - 4WD,5.4,8,CNG,160,STANDARD PICKUP TRUCKS 4WD
FORD,E250 ECONOLINE (natural gas) - 2WD,5.4,8,CNG,170,"VANS, CARGO TYPE"
FORD,E250 ECONOLINE (natural gas) - 2WD,5.4,8,CNG,80,"VANS, CARGO TYPE"
FORD,F150 LPG - 2WD,5.4,8,LPG,290/370*,STANDARD PICKUP TRUCKS 2WD
FORD,F250 LPG - 2WD,5.4,8,LPG,260/290/370**,STANDARD PICKUP TRUCKS 2WD
ok, so do i need to write a file carsclass.java or is the line:
ArrayList<CarsClass> carsClass = new ArrayList<CarsClass>(" write all fields");
going to define my carsclass objects? how do i write my fields for each of the 7 categories?
i believe i can easily add to and print the arraylist, but i'm confused how to go about creating this arraylist in the first place. do i just create carclass.java and save them all as strings? i guess my question is mainly how should i structure this? any suggestions/help is appreciated.
Edited by: scottc on Nov 15, 2007 5:55 PM

String.split uses regular expressions.Ahh yeah ummm (slaps forehead) I'd forgotten that... so maybe StringTokeniser is more accessible for noob's. Sorry.
Anyway... if all you want/need to so is store a bunch of String field values then how about using an array of String's instead of individual fields... maybe something like:
forums\Car.java
* Car Data Transfer Object. All fields are final, making objects of this class
* thread safe(r).
* @author keith
package forums;
import krc.utilz.stringz.Arrayz;
public class Car
  // class attributes                       // variables //isn't actually wrong, it's just not quit right.
  private final String[] fields;            // final means values are write once, read many times, which is thread safe(r).
   * Initialises the new Cars fields to the given fields array.
   * @param fields - an array of any (reasonable) length
  public Car(String[] fields) {             // no need to comment a constructor as a constructor.
    this.fields = fields;                   // much better to provide javadoc comments explaining
  }                                         // what the method does and how to use it.
   * Returns this Car's fields as one long string.
  public String toString() {                // It's actually GOOD to be a lazy programmer.
    return Arrayz.join(", ", this.fields);  // I have reused my Arrayz.join in several projects.
                                            // I think you can use Array.toString (new in 1.6) instead.
krc\utilz\stringz\Arrayz.java
package krc.utilz.stringz;
import java.util.List;
import java.util.ArrayList;
public class Arrayz
    * returns true if the given value is in the args list, else false.
    * @param value - the value to seek
    * @param args... - variable number of String arguments to look in
  public static boolean in(String value, String... args) {
    for(String a : args) if(value.equals(a)) return true;
    return false;
    * append the elements of array into one string, seperated by FS
    * @param a  - an array of strings to join together
    * @param FS - Field Seperator string, optional default=" "
    * @example
    *  String[] array = {"Bob","The","Builder"};
    *  System.out.println(join(array);
    *  --> Bob The Builder
    *  System.out.println("String[] array = {\""+join(array, "\",\"")+"\"};");
    *  --> String[] array = {"Bob","The","Builder"};
  public static String join(String FS, String[]... arrays) {
    StringBuffer sb = new StringBuffer();
    for (String[] array : arrays)
      sb.append(join(array, FS));
    return(sb.toString());
  public static String join(String[] array) {
    return(join(array, " "));
  public static String join(String[] a, String FS) {
    if (a==null) return null;
    if (a.length==0) return "";
    StringBuffer sb = new StringBuffer(a[0]);
    for (int i=1; i<a.length; i++) {
      sb.append(FS+a);
return sb.toString();
* append all the elements of the given arrays into one big array
* @param String[]... arrays - to be concatenated
* @return String[] - one big array
public static String[] concatenate(String[]... arrays) {
List<String> list = new ArrayList<String>();
for(String[] array : arrays) {
for(String item : array) {
list.add(item);
return(list.toArray(new String[0]));
I guess that Arrayz class might be a bit beyond you at the moment so don't worry too much if you can't understand the code... there are no nasty surprises in it... just cut and paste the code, change the package name, and use it (for now).

Similar Messages

  • Question about reading csv file into internal table

    Some one (thanks those nice guys!) in this forum have suggested me to use FM KCD_CSV_FILE_TO_INTERN_CONVERT to read csv file into internal table. However, it can be used to read a local file only.
    I would like to ask how can I read a CSV file into internal table from files in application server?
    I can't simply use SPLIT as there may be comma in the content. e.g.
    "abc","aaa,ab",10,"bbc"
    My expected output:
    abc
    aaa,ab
    10
    bbb
    Thanks again for your help.

    Hi Gundam,
    Try this code. I have made a custom parser to read the details in the record and split them accordingly. I have also tested them with your provided test cases and it work fine.
    OPEN DATASET dsn FOR input IN TEXT MODE ENCODING DEFAULT.
    DO.
    READ DATASET dsn INTO record.
      PERFORM parser USING record.
    ENDDO.
    *DATA str(32) VALUE '"abc",10,"aaa,ab","bbc"'.
    *DATA str(32) VALUE '"abc","aaa,ab",10,"bbc"'.
    *DATA str(32) VALUE '"a,bc","aaaab",10,"bbc"'.
    *DATA str(32) VALUE '"abc","aaa,ab",10,"b,bc"'.
    *DATA str(32) VALUE '"abc","aaaab",10,"bbc"'.
    FORM parser USING str.
    DATA field(12).
    DATA field1(12).
    DATA field2(12).
    DATA field3(12).
    DATA field4(12).
    DATA cnt TYPE i.
    DATA len TYPE i.
    DATA temp TYPE i.
    DATA start TYPE i.
    DATA quote TYPE i.
    DATA rec_cnt TYPE i.
    len = strlen( str ).
    cnt = 0.
    temp = 0.
    rec_cnt = 0.
    DO.
    *  Start at the beginning
      IF start EQ 0.
        "string just ENDED start new one.
        start = 1.
        quote = 0.
        CLEAR field.
      ENDIF.
      IF str+cnt(1) EQ '"'.  "Check for qoutes
        "CHECK IF quotes is already set
        IF quote = 1.
          "Already quotes set
          "Start new field
          start = 0.
          quote = 0.
          CONCATENATE field '"' INTO field.
          IF field IS NOT INITIAL.
            rec_cnt = rec_cnt + 1.
            CONDENSE field.
            IF rec_cnt EQ 1.
              field1 = field.
            ELSEIF rec_cnt EQ 2.
              field2 = field.
            ELSEIF rec_cnt EQ 3.
              field3 = field.
            ELSEIF rec_cnt EQ 4.
              field4 = field.
            ENDIF.
          ENDIF.
    *      WRITE field.
        ELSE.
          "This is the start of quotes
          quote = 1.
        ENDIF.
      ENDIF.
      IF str+cnt(1) EQ ','. "Check end of field
        IF quote EQ 0. "This is not inside quote end of field
          start = 0.
          quote = 0.
          CONDENSE field.
    *      WRITE field.
          IF field IS NOT INITIAL.
            rec_cnt = rec_cnt + 1.
            IF rec_cnt EQ 1.
              field1 = field.
            ELSEIF rec_cnt EQ 2.
              field2 = field.
            ELSEIF rec_cnt EQ 3.
              field3 = field.
            ELSEIF rec_cnt EQ 4.
              field4 = field.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      CONCATENATE field str+cnt(1) INTO field.
      cnt = cnt + 1.
      IF cnt GE len.
        EXIT.
      ENDIF.
    ENDDO.
    WRITE: field1, field2, field3, field4.
    ENDFORM.
    Regards,
    Wenceslaus.

  • Read CSV file into a 1-D array

    Hi
    I would like to read a csv file into a cluster of 4 elements which would then be read into a 1-D array.
    My cluster contains a typedef, a double, a boolean, and another typedef.
    Basically it could be seen as:
    Bob Runs, 4, T, Bob
    Mary sits, 5, F, Mary
    Bob Sits, 2, F, Bob
    Mary Runs, 9, T, Mary
    (keeps growing)
    Are there any good examples for what I am trying to put together that I could leverage, or is it better to use a different input file than a csv. I am trying to make my program more flexable and easier to make adjustments even after the executable is created.  My line items seem to be growing exponentially and is getting difficult to manage in the LV window.
    Thanks
    Solved!
    Go to Solution.

    Unless your CSV file is huge, I'd use "Read from Spreadsheet File" with the delimiter set as "," and the type as string.  This will give you a 2D array of strings.  You could then separate out each column of the array, convert to the appropriate data type, and use Index & Bundle Cluster Array to build your array of clusters.  Something like this (except I'm using a string constant in place of reading from the file).

  • How to read/write .CSV file into CLOB column in a table of Oracle 10g

    I have a requirement which is nothing but a table has two column
    create table emp_data (empid number, report clob)
    Here REPORT column is CLOB data type which used to load the data from the .csv file.
    The requirement here is
    1) How to load data from .CSV file into CLOB column along with empid using DBMS_lob utility
    2) How to read report columns which should return all the columns present in the .CSV file (dynamically because every csv file may have different number of columns) along with the primariy key empid).
    eg: empid report_field1 report_field2
    1 x y
    Any help would be appreciated.

    If I understand you right, you want each row in your table to contain an emp_id and the complete text of a multi-record .csv file.
    It's not clear how you relate emp_id to the appropriate file to be read. Is the emp_id stored in the csv file?
    To read the file, you can use functions from [UTL_FILE|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#BABGGEDF] (as long as the file is in a directory accessible to the Oracle server):
    declare
        lt_report_clob CLOB;
        l_max_line_length integer := 1024;   -- set as high as the longest line in your file
        l_infile UTL_FILE.file_type;
        l_buffer varchar2(1024);
        l_emp_id report_table.emp_id%type := 123; -- not clear where emp_id comes from
        l_filename varchar2(200) := 'my_file_name.csv';   -- get this from somewhere
    begin
       -- open the file; we assume an Oracle directory has already been created
        l_infile := utl_file.fopen('CSV_DIRECTORY', l_filename, 'r', l_max_line_length);
        -- initialise the empty clob
        dbms_lob.createtemporary(lt_report_clob, TRUE, DBMS_LOB.session);
        loop
          begin
             utl_file.get_line(l_infile, l_buffer);
             dbms_lob.append(lt_report_clob, l_buffer);
          exception
             when no_data_found then
                 exit;
          end;
        end loop;
        insert into report_table (emp_id, report)
        values (l_emp_id, lt_report_clob);
        -- free the temporary lob
        dbms_lob.freetemporary(lt_report_clob);
       -- close the file
       UTL_FILE.fclose(l_infile);
    end;This simple line-by-line approach is easy to understand, and gives you an opportunity (if you want) to take each line in the file and transform it (for example, you could transform it into a nested table, or into XML). However it can be rather slow if there are many records in the csv file - the lob_append operation is not particularly efficient. I was able to improve the efficiency by caching the lines in a VARCHAR2 up to a maximum cache size, and only then appending to the LOB - see [three posts on my blog|http://preferisco.blogspot.com/search/label/lob].
    There is at least one other possibility:
    - you could use [DBMS_LOB.loadclobfromfile|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978]. I've not tried this before myself, but I think the procedure is described [here in the 9i docs|http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl12bfl.htm#879711]. This is likely to be faster than UTL_FILE (because it is all happening in the underlying DBMS_LOB package, possibly in a native way).
    That's all for now. I haven't yet answered your question on how to report data back out of the CLOB. I would like to know how you associate employees with files; what happens if there is > 1 file per employee, etc.
    HTH
    Regards Nigel
    Edited by: nthomas on Mar 2, 2009 11:22 AM - don't forget to fclose the file...

  • How to read a CSV file into the portal

    hi all,
    I want to read the content of CSV file that is avaliable in my desktop.
    plz help me with suitable code
    Regards
    Savitha
    Edited by: Savitha S R on Jun 1, 2009 8:25 AM

    Please use this code for that
    REPORT  znkp_upload_csv line-size 400.
    DATA : v_filename TYPE string.
    PARAMETER : p_file LIKE rlgrap-filename DEFAULT 'C:\Documents and Settings\Administrator\Desktop\JV.csv' .
    *Types for Reading CSV file
    TYPES : BEGIN OF x_csv,
              text(400) TYPE c,
            END OF x_csv.
    *Global internal table for reading CSV file
    DATA : lt_csv TYPE TABLE OF x_csv.
    *Global work area for reading CSV file
    DATA : wa_csv LIKE LINE OF lt_csv.
    v_filename = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = v_filename
      FILETYPE                      = 'ASC'
      HAS_FIELD_SEPARATOR           = ' '
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        data_tab                      = lt_csv
    EXCEPTIONS
       file_open_error               = 1
       file_read_error               = 2
       no_batch                      = 3
       gui_refuse_filetransfer       = 4
       invalid_type                  = 5
       no_authority                  = 6
       unknown_error                 = 7
       bad_data_format               = 8
       header_not_allowed            = 9
       separator_not_allowed         = 10
       header_too_long               = 11
       unknown_dp_error              = 12
       access_denied                 = 13
       dp_out_of_memory              = 14
       disk_full                     = 15
       dp_timeout                    = 16
       OTHERS                        = 17
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    DATA : BEGIN OF item OCCURS 0 ,
            t1(20) TYPE c,
            t2(20) TYPE c,
            t3(20) TYPE c,
            t4(20) TYPE c,
            t5(20) TYPE c,
            t6(20) TYPE c,
            t7(20) TYPE c,
            t8(20) TYPE c,
           END OF item.
    DATA : txt(1) TYPE c. " 1-Header 2-Item
    LOOP AT lt_csv into wa_csv.
    split wa_csv-text at ',' into item-t1
                                  item-t2
                                  item-t3
                                  item-t4
                                  item-t5
                                  item-t6
                                  item-t7
                                  item-t8.
    append item.
    clear item.
    ENDLOOP.
    Check ITEM TABLE
    Regards
    Naresh

  • Combine multiple CSV files into a single multi-column CSV file

    Hey Scripting Guy!
    I have what is probably a simple issue, but I haven't been able to find the right answer.
    I have 18 CSV files that each contain the same header and a single value as shown below:
    "Sum"
    "90"
    These files are the results of SMTP traffic by domain.
    All I want to do is to combine the 18 CSV files into a single file with the content of each file in a separate column, using the file name as the column header.
    For example:
    file1.csv
      "Sum"
      "90"
    file2.csv
      "Sum"
      "325"
    file2.csv
      "Sum"
      "3534"
    The desired ouput is:
    "file1.csv","file2.csv","file3.csv"
    "Sum","Sum","Sum"
    "90","325","3534"
    I don't need to row of Sum's if it is easy to leave out.  It would be even better if this could be put into an Excel spreadsheet.
    Thanks for your help!

    Can you post your script?
    If you are not a technician and do not want to write a script then you should try hiring a consultant.
    If you want to learn how to write a script then start here:
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    By the way...your request makes no logical or technical sense.  What is the point of doing this?  There is no relationship between these files.
    ¯\_(ツ)_/¯

  • Uploading csv file into database using apex

    Dear all
    I am using apex 4 and oracle express 10g, i need to upload .csv file into the database for one of my appls, i have referred discussion forum for solutions, i found also, but some how its not working for me.
    below mentioned is error and the code
    ERROR:
    ORA-06550: line 38, column 8: PLS-00221: 'V_DATA_ARRAY' is not a procedure or is undefined ORA-06550: line 38, column 8: PL/SQL: Statement ignored ORA-06550: line 39, column 8: PLS-00221: 'V_DATA_ARRAY' is not a procedure or is undefined ORA-06550: line 39, column 8: PL/SQL: Statement ignored ORA-06550: line 40, column 8: PLS-00221: 'V_DATA_ARRAY' is not a procedure or is undefined ORA-06550: line 40, column 8: PL/SQL: Statement ignored ORA-06550: line 41, column 8: PLS-00221: 'V_DATA_ARRAY' is not a proc
    Error
    OK
    CODE:
    DECLARE
    v_blob_data BLOB;
    v_blob_len NUMBER;
    v_position NUMBER;
    v_raw_chunk RAW(10000);
    v_char CHAR(1);
    c_chunk_len number := 1;
    v_line VARCHAR2 (32767) := NULL;
    v_data_array wwv_flow_global.vc_arr2;
    BEGIN
    -- Read data from wwv_flow_files
    select blob_content into v_blob_data
    from wwv_flow_files where filename = 'DDNEW.csv';
    v_blob_len := dbms_lob.getlength(v_blob_data);
    v_position := 1;
    -- Read and convert binary to char
    WHILE ( v_position <= v_blob_len ) LOOP
    v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
    v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
    v_line := v_line || v_char;
    v_position := v_position + c_chunk_len;
    -- When a whole line is retrieved
    IF v_char = CHR(10) THEN
    -- Convert comma to : to use wwv_flow_utilities
    v_line := REPLACE (v_line, ',', ':');
    -- Convert each column separated by : into array of data
    v_data_array := wwv_flow_utilities.string_to_table (v_line);
    -- Insert data into target table
    EXECUTE IMMEDIATE 'insert into TABLE_X (v1, v2, v3, v4 ,v5, v6, v7,v8 ,v9, v10, v11)
    values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11)'
    USING
    v_data_array(1),
    v_data_array(2),
    v_data_array(3),
    v_data_array(4);
    v_data_array(5);
    v_data_array(6);
    v_data_array(7);
    v_data_array(8);
    v_data_array(9);
    v_data_array(10);
    v_data_array(11);
    -- Clear out
    v_line := NULL;
    END IF;
    END LOOP;
    END;
    what i understand from this is system does not identify v_data_array as array for some reasons, please help me.
    initially system was giving error for hex_to_decimal, but i managed to get this function on discussion forum and now it seems to be ok. but v_data_array problem is still there.
    thanks in advance
    regards
    Uday

    Hi,
    Mistakes in your sample I did correct
    Problem 1
    select blob_content into v_blob_data
    from wwv_flow_files where filename = 'DDNEW.csv'; to
    select blob_content into v_blob_data
    from wwv_flow_files where name = :P1_FILE;Problem 2
    EXECUTE IMMEDIATE 'insert into TABLE_X (v1, v2, v3, v4 ,v5, v6, v7,v8 ,v9, v10, v11)
    values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11)'
    USING
    v_data_array(1),
    v_data_array(2),
    v_data_array(3),
    v_data_array(4);
    v_data_array(5);
    v_data_array(6);
    v_data_array(7);
    v_data_array(8);
    v_data_array(9);
    v_data_array(10);
    v_data_array(11);  to
    EXECUTE IMMEDIATE 'insert into TABLE_X (v1, v2, v3, v4 ,v5, v6, v7,v8 ,v9, v10, v11)
    values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11)'
    USING
    v_data_array(1),
    v_data_array(2),
    v_data_array(3),
    v_data_array(4),
    v_data_array(5),
    v_data_array(6),
    v_data_array(7),
    v_data_array(8),
    v_data_array(9),
    v_data_array(10),
    v_data_array(11);  And I did create missing table
    CREATE TABLE TABLE_X
        v1  VARCHAR2(255),
        v2  VARCHAR2(255),
        v3  VARCHAR2(255),
        v4  VARCHAR2(255),
        v5  VARCHAR2(255),
        v6  VARCHAR2(255),
        v7  VARCHAR2(255),
        v8  VARCHAR2(255),
        v9  VARCHAR2(255),
        v10 VARCHAR2(255),
        v11 VARCHAR2(255)
      );Regards,
    Jari
    Edited by: jarola on Nov 19, 2010 3:03 PM

  • How to covert a CSV file into a file of spreadsheet format(staroffice)?

    Hello everybody,
    I want to create a java that can convert CSV file into spreadsheet. But i dont have any idea how to create a Spreadsheet (i just know it have a Binary File format).
    So anyone can give me some reference or program sample, some advises ????
    Pls help
    thx

    Hi
    set the content type as given below and PrintWriter class to write into excel sheet
    response.setContentType("application/x-msexcel");
    response.setHeader("Content-Disposition", "attachment; filename=" + "abc Download" + ".xls");

  • Importing a csv file into addressbook

    So I did a search & found this question has come up quite often, but with the person having a slightly different problem, so here goes.
    I am trying to import a csv file into address book, when I go import -> text tile it comes up like it should do and I pick the file, if I select ok at this point, it will quite happily import all of the data no trouble (but in the wrong categories). So I make the changes to what I want ie. Phone other --> Phone (work). Then when I click ok, the button goes from blue to white but nothing happens.
    When I open the csv file in textedit I can see all the values separated by commas.
    Any Ideas?

    I too just had this problem. To clarify all fields work and you can map them. I found that the Outlook CSV file had two problems which were tripping up the AddressBook import function. Note these were both in street address fields so I suspect the poster who said that addresses don't work may have been having that problem.
    The CSV load program does not work if you have commas "," in your data. In my case this was very common for some European addresses as well as some company names. And then the second problem was if there was a carriage return or new line character in a field. This later one was a problem with the address fields. I suspect an AddressBook export to CSV might have this same issue. Specifically, when there were multiple lines to the street address, they had been entered as multiple lines in street address one, as opposed to entering them in multiple fields such as "street 1", "street 2", etc.
    To solve the problem I opened the CSV file using Numbers and did a global find and replace on: commas, substituting the string --- and on the newline character "¶" (ALT+Rreturn) with *.
    Note to reduce some of the remapping I also changed all of the labels with "business" in the header row of the CSV file to "work". This made it a little easier for the AddressBook import function to map fields more correctly.
    After these set of changes rather than the alternating blue then white with nothing behavior it cleanly loaded all of my names. I could then search for "---" and "*" in addressbook's search field to identify all addresses which I had to clean up.
    I hope that is helpful to someone else. The import function really does work. However, it is not robust enough to deal with certain oddities in one's data.

  • Importing a CSV file into AD 2012r2

    Hi Guys
    Just wondering if anyone can help, I am a newbie on scripting and finding it really difficult to understand how to import a csv file into AD
    I have created the CSV file with the following headers, see below but I am unable to write a powershell script to import them into AD which work, I have tried multiple help guides but still cannot do it for the life of me.
    Any help on this would be really appreciated 
    objectClass user
    cn Jo bloggs
    givenName jo
    sn blogs
    mail [email protected]
    sAMAccountname j.blogs
    AccountPassword Pa$$w0rd
    ChangePasswordAtLogon true
    PasswordNeverExpires false
    ou OU=staff,DC=test,DC=com

    Import-Csv C:\User.csv| %{New-ADUser -SamAccountName $_.SamAccountName `
    -UserPrincipalName $_.userprinicpalname `
    -Name $_.name `
    -Mail = $_.mail `
    -DisplayName $_.name `
    -GivenName $_.GivenName `
    -Path "OU=Test Users,DC=XXX,DC=XXX" `
    -PasswordNeverExpires $false `
    -ChangePasswordAtLogon $true `
    -AccountPassword (ConvertTo-SecureString "test41;" -AsPlainText -force) `
    -Enabled $True -PasswordNeverExpires $True -PassThru ` }
    help New-ADUser -Examples
    You can try the below sample code
    Regards Chen V [MCTS SharePoint 2010]

  • How to convert csv files into java bean objects?

    Hi,
    I have a CSV file, I want to store the data availabale in that csv file into java bean, I am new to this csv files how can I convert CSV files into java beans.
    Please help me.
    Adavanced Thanks,
    Mahendra

    You can use the java.io API to read (and write) files. Use BufferedReader to read the CSV file line by line. Use String#split() to split each line into an array of parts which were separated by comma (or semicolon). If necessary run some escaping of quotes. Finally collect all parts in a two-dimensional List of Strings or a List of Javabeans.
    java.io API: [http://www.google.com/search?q=java.io+javase+api+site:sun.com]
    java.io tutorial: [http://www.google.com/search?q=java.io+tutorial+site:sun.com]
    Basic CSV parser/formatter example: [http://balusc.blogspot.com/2006/06/parse-csv-upload.html]

  • Uploading CSV file into internal table

    Hi,
    I want to upload a CSV file into internal table.The flat file is having values as below:
    'AAAAA','2003-10-11 07:52:37','167','Argentina',NULL,NULL,NULL,NULL,NULL,'MX1',NULL,NULL,'AAAA BBBB',NULL,NULL,NULL,'1',NULL,NULL,'AR ',NULL,NULL,NULL,'ARGENT','M1V','MX1',NULL,NULL,'F','F','F','F','F',NULL,'1',NULL,'MX','MMI ',NULL
    'jklhg','2004-06-25 08:01:57','456','hjllajsdk','MANAGUA   ',NULL,NULL,'265-5139','266-5136 al 38','MX1',NULL,NULL,'hjgkid GRÖBER','sdfsdf dfs asdfsdf 380 ad ased,','200 as ads, sfd sfd abajao y 50 m al sdf',NULL,'1',NULL,NULL,'NI ',NULL,NULL,NULL,'sdfdfg','M1V','dds',NULL,NULL,
    Here I can not even split at ',' because some of the values are having value like NULL and some have values with comma too,
    The delimiter is a quote and the separator is a comma here.
    Can anyone help on this?
    Thanks.
    Edited by: Ginger on Jun 29, 2009 9:08 AM

    As long as there can be a comma in a text literal you are right that the spilt command doesn't help. However there is one possibility how to attack this under one assumption:
    - A comma outside a text delimiter is always considered a separator
    - A comma inside a text delimiter is always considered a comma as part of the text
    You have to read you file line by line and then travel along the line string character by character and setting a flag or counter for the text delimiters:
    e.g.
    "Text","Text1, Text2",NULL,NULL,"Text"
    String Index  1: EQ " => lv_delimiter = 'X'
    String Index  2: EQ T => text literal (because lv_delimiter = 'X')
    String Index  3: EQ e => text literal (because lv_delimiter = 'X')
    String Index  4: EQ x => text literal (because lv_delimiter = 'X')
    String Index  5: EQ t => text literal (because lv_delimiter = 'X')
    String Index  6: EQ " => lv_delimiter = ' ' (because it was 'X' before)
    String Index  7: EQ , => This is a separator because lv_delimiter = ' '
    String Index  8: EQ " => lv_delimiter = 'X' (because it was ' ' before)
    String Index  9: EQ T => text literal (because lv_delimiter = 'X')
    String Index 10: EQ e => text literal (because lv_delimiter = 'X')
    String Index 11: EQ x => text literal (because lv_delimiter = 'X')
    String Index 12: EQ t => text literal (because lv_delimiter = 'X')
    String Index 13: EQ 1 => text literal (because lv_delimiter = 'X')
    String Index 14: EQ , => text literal (because lv_delimiter = 'X')
    String Index 15: EQ T => text literal (because lv_delimiter = 'X')
    Whenever you hit a 'real' separator (lv_delimiter = ' ') you pass the value of the string before that up to the previous separator into the next structure field.
    This is not an easy way to do it, but if you might have commas in your text literal and NULL values I gues it is probably the only way to go.
    Hope that helps,
    Michael

  • Dropping csv file into a cell?

    After updating "Numbers", I can no longer call drop csv files into a cell and have the row complete. What am I missing here?

    Hello fellow sufferers of CSV headaches from commas within fields and ; instead of , etc.. They've been around as long as I can remember. 
    If you don't want to use Excel (which is good at this sort of thing), this script should help. (Dropbox download, AppleScript file). The effect is similar to Excel's Text to Columns but the usage is slightly different.
    If you end up with text all in one column as Cuky describes, you simply select the body cells in that column containing the text, run the script, click on a cell (the first cell in the body of the next column to the right often works best) and paste.
    The results here look like this:
    I deliberately made the unexpanded column untidy and threw some difficult things at it, and it did a pretty good job in testing here. Return or shift-return within a field, even if quoted, will cause Numbers to move to a new line, but that's a Numbers thing that can't be helped. Otherwise, it handles the usual csv conventions better than expected.
    If your separator is ; instead of , there is a place you can change that it the script.
    If you frequently import data, this is easily placed in the menu, either as an Automator Service or under Scripts.
    And it could be modified to read a csv file rather than grabbing values already in a Numbers column, making it almost as convenient as the old drag and drop. It could ask for the csv file and put the results on the clipboard for pasting into a table.
    If there is interest in that let me know. And suggestions/feedback on this one welcome.
    SG

  • Looking for a Notes app that I can import CSV files into?

    As the title says, I'm looking for a good notes application for my iPhone that I can import CSV files into. I have tried both Appigo and Notespark, but I can't easily scroll through them, as I have 2,000+ notes. Is there any app that I can import my notes into and also scroll through quickly? I'd like something that works similarly to how you scroll through songs on the iPhone/iTouch, with the column on the right where you can skip to songs (notes, in this case) that start with a certain letter.
    Thanks!

    Hi Tx Tar Heel,
    I've been using Office2HD: https://itunes.apple.com/us/app/office2-hd/id364361728?mt=8
    Its cheaper than Numbers and it also works for Word and PowerPoint files too. I like the Dropbox integration. I can start on my Office docs (Word, Excel, PowerPoint) in the office and then edit those files with Office2HD when I'm out of the office. Files saves right back to Dropbox so that when I get back to the office the files are already updated. Not bad for a $7.99 app!
    Hope this helps!
    ~Joe

  • Loading data from .csv file into Oracle Table

    Hi,
    I have a requirement where I need to populate data from .csv file into oracle table.
    Is there any mechanism so that i can follow the same?
    Any help will be fruitful.
    Thanks and regards

    You can use Sql Loader or External tables for your requirement
    Missed Karthick's post ...alredy there :)
    Edited by: Rajneesh Kumar on Dec 4, 2008 10:54 AM

Maybe you are looking for

  • READ REPORT for specific version

    I'm using function module RPY_PROGRAM_READ that calls READ REPORT. However I'd like to get the code for a previous version. The READ REPORT is very limited with it's options and I can't find a function module (RFC enabled) that does this. Any suggest

  • HT1349 i did the update to my i pad and it said error 1604 now it wont charge so i cant turn it on

    hi i plugged in my i pod the other day to my computer and im running xp with the original ipad it did the update now it wont charge error 1604

  • Speakers that look very nice with aluminum iMac?

    I'm looking to purchase speakers for my iMac and I haven't found any that look great and also get good reviews. I'm willing to spend up to about $200 CDN. I have the aluminum iMac. I will be using the speakers mostly to watch TV/video so I don't need

  • WIN/Vista, PSE 7.0:  Organizer problems with dates

    Im working with our scanned photos now, so there is no EXIF data and the only dates are the scanned date and any later corrections in Photoshop CS3 before or after importing into PSE 7.0. I now have two date related problems that I didnt have with PE

  • How can I set 100% width my slideshow on mobile version

    Hello! It's been a while I needed to ask this question here but a huge problem of authentication from ADOBE forum took months to be solved by them. Anyway, I have a website made with muse (desktop). I tried to decline it in tablet and photo version a