Storing file contents in a Collection

Hi All,
Im trying to read a csv file, break the lines by comma, then store them and sort them.
I have the test code working from: http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
I am reading the file, but when I System.out.println() I keep getting the last line of the file only. Why is that?
     try {
          BufferedReader in = new BufferedReader(new FileReader("/Users/custodian/Desktop/list.csv"));
String line;
//Start reading the file while
while ((line = in.readLine()) != null) {
// System.out.println(line);
StringTokenizer st = new StringTokenizer(line, ",");
//Counting tokens while
while (st.hasMoreTokens()){
     count++;
     //System.out.println(st.nextToken());
     fullname = st.nextToken();
     StringTokenizer wsp = new StringTokenizer(fullname, " ");
     //breaking full name apart while
     while(wsp.hasMoreTokens()){
          fname = wsp.nextToken();
          lname = wsp.nextToken();
     email = st.nextToken();
     phone = st.nextToken();
     streetaddress = st.nextToken();
     city = st.nextToken();
     state = st.nextToken();
     zip = st.nextToken();
     contactArray = new Contact(fname, lname, email, phone, streetaddress, city, state, zip);
     System.out.println(contactArray.toString());
     List <Contact> contacts = Arrays.asList(contactArray);
     Collections.sort(contacts);
     System.out.println(contacts);

Hi,
im trying to sort by state then write to another file:
I keep getting an error on Collections.sort(contacts, new StateComparator());
Collections.sort(contacts, new StateComparator());
                         try {
                              BufferedWriter out = new BufferedWriter(new FileWriter("state-sort.csv"));
                              //PrintWriter p = new PrintWriter(out);
                              out.write(firstLine + "\n");
                              Iterator it = contacts.listIterator();
                              while(it.hasNext()) {
                              Object o = it.next();     
                              out.write(o.toString() + "\n");
                              out.flush();
                              out.close();
                         }catch(FileNotFoundException ee) {}
                         catch(IOException ioe) {}
Here is my Comparator
package mybeans;
class StateComparator implements Comparable
     String state;
     public String getState() { return state; }
     public int compare(Object obj1, Object obj2)
          if(obj1 == obj2)
               return 0;
          Contact c1 = (Contact) obj1;
          Contact c2 = (Contact) obj2;
          return c1.getState().compareTo(c2.getState());
     public int compareTo(Object obj)
          Contact c = (Contact) obj;
          return (state).compareTo(c.state + c.state);
Any help appreciated.

Similar Messages

  • How can I transfer a XML file content to a MS SQL database by stored procedure using LabWindows/CVI SQL Toolkit?

    Hi,
    I have a problem to transfer a XML file content to a MS SQL database by a given/fixed stored procedure. I'm able to transfer the content of the file by using following method ...
    hstmt = DBPrepareSQL (hdbc, EXEC usp_InsertReport '<Report> ..... </Report>');
    resCode = DBExecutePreparedSQL (hstmt);
    resCode = DBClosePreparedSQL (hstmt);
    ... but in this case I'm not able to fetch the return value of the stored procedure! 
    I have tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL) but I miss a datatype for xml?!?
    Any idea how to solve my problem?
    KR Cake  
    Solved!
    Go to Solution.

    After some additional trials I found a solution by calling the stored procedure in this way
    DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_STORED_PROC);
    DBPrepareSQL (hdbc, "usp_InsertReport");
    DBCreateParamInt (hstmt, "", DB_PARAM_RETURN_VALUE, -1);
    DBCreateParamChar (hstmt, "XMLCONTENT", DB_PARAM_INPUT, sz_Buffer, (int) strlen(sz_Buffer) + 1 );
    DBExecutePreparedSQL (hstmt);
    DBClosePreparedSQL (hstmt);
    DBGetParamInt (hstmt, 1, &s32_TestId);
    where sz_Buffer is my xml file content and s32_TestID the return value of the stored procdure (usp_InsertReport(@XMLCONTENT XML))
    Now I face the problem, that DBCreateParamChar limits the buffer size to 8000 Bytes.
    Any idea to by-pass this shortage??

  • Error on update of document stored in content server

    Error on update of document stored in content server
    On a regular basis (but not reproducible) we find that after updating a document, it is deleted from content server (or at least it cannot be retrieved).  These problems have only been experienced since we switched to using content server as our storage repository, as opposed to R/3.
    We create and maintain documents through a bespoke transaction, which calls standard SAP functions BDS_BUSINESSDOCUMENT_CREA_TAB and cl_bds_document_set=>update_with_table.
    Whilst the errored documents are listed in the BDS via transaction OAOR (business document navigator), an error is received when you try to display it (in our case an MS-Word error indicating file/pathname invalid). 
    We are satisfied that file/pathname are valid and find that this occurs occasionally when a document has been updated.  It appears that the document has been deleted. 
    This bespoke transaction has been running successfully for almost two years, and these problems have only been experienced after switching to content server as a storage repository (as opposed to R3 previously).  Has anyone else experienced these problems? 
    We are running :
    R/3 Enterprise 620,
    SAP HTTP Content Server Version 6.30 Patch 13
    SAPDB version 7.3.0.54

    Hi Sonny,
    To check the connectivity between your content server and Workstation and SAP Server.
    Pls goto the command prompt of your workstation
    give the command like this example.
    C:\>Ping 117.123.45.201
    you will get the reply from the server. here 117.123.45.201 is your content server IP.
    If you are getting the reply then it means that your contentserver and workstation are connected propely.
    Like that pls check the connectivity between your systems.
    Pls check the hosts file of your systems also.
    If the hosts file entry is not maintained, you can check-out file from content server but you cannot check-in the original.
    Pls let me know what kind of error Message you are getting?
    From where you are trying to check-in the Original? From the DIR screen or from CAD Desktop screen?
    Regards,
    MRK
    (reward points if useful)

  • How to store file content in BLOB field MySql database using java

    Hi!
    i want to store the file content in a BLOB field in MySql database using java.
    Please help me out..........
    thanx in advance...
    bye

    i stored images in db, and retrieved them. like that cant i store pdf file in db, and retrieve it back using oracle db?
    Plz help me out how to put a file in db. i need complete code. thanks in advance.

  • How do I make a table of contents for a collection of six short stories that is after the legal page and NOT in the front on an unnumbered page?

    How do I make a table of contents for a collection of six short stories that is after the legal page and NOT in the front on an unnumbered page?
    When I first started I made a title page and then pasted in my first story from a .TXT file. After cleaning up I went back to the front a couple of empty lines ahead of the story and typed in the story title.  Unlarged the font size and centered it, then

    You can't do that. This is what the Pages User Guide, downloadable from your Pages Help menu, says:
    Creating and Updating a Table of Contents
    Each table of contents (TOC) you create using a Word Processing template lists only the content that follows it, up until the next table of contents. If you want a master table of contents for the entire document, it must be the only table of contents, and it must be at the beginning of the document.
    You can do it manually though.

  • How to find out if file contents under some document library SPListItem has changed

    hi,
    I am building a Sync tool which will Sync SharePoint document library to some other service(e.g. FTP). I have added event handlers on the document library for ItemAdded, ItemUpdated etc.. etc.
    Now i have one problem, when ever a file is updated (either custom properties and/or file content) then there is no way to check if its updating of content or custom fields. So everytime i need to upload my file to that FTP location. I want to get some indication
    that this time file content is updated not the custom fields, or file content with custom fields are updated.
    I have checked After and Before properties but its of no use. When ever you rename a file or just open the edit dialogbox and save it without updating any thing, all after and before properties are same :(
    Need some solution for this, any help suggestion is appriciated.
    Syed Shoaib Adil Senior SharePoint Developer Boston, Ma, USA

    Sorry for late reply.
    1st link (storing file hash/MD5) is not a solution for me as i have many Office documents
    2nd link doesnt have nay answers
    Archive Folder is not a solution. How can i find if current item SPFile has content changes?
    I already have my custom fields with each SPListItem. How can i find in itemUpdating/ed that if file content is changed? to make my custom field ture?
    Syed Shoaib Adil Senior SharePoint Developer Boston, Ma, USA

  • Using File Browse to update stored file

    Hi all,
    I have a form with a File Browse item on it which is (surprisingly!) used to upload a file and associate with a record. The filename is stored in a varchar column in the table. This works fine when I create (INSERT) the initial record and I can retrieve the stored file just fine. However the problem I have is when I want to update the uploaded file. It seems the normal mechanisms for update / save requests don't apply to uploaded files. My other attributes get updated fine but the new uploaded filename is not reflected in the table.
    I've put together a simple example of this on a when apex.oracle.com :
    http://apex.oracle.com/pls/otn/f?p=40740
    Which has two fields, a file name and an 'attribute'. Try as I might I can't update the file name although the attribute changes just fine.
    Any suggestions will be much appreciated. I realise I may be missing something fundamental here and am more than happy to be enlightened.
    FYI, the purpose for such functionality is to allow users of our system to store a photograph of themselves along with their details. This functionality is required to allow the photograph to be updated if required.
    Thanks,
    Steve

    If i am not mistaking, using a file browser item type will not set the uploaded file (blob) in this item, to be processed in the standard processing on you're page.
    In a recent project i wrote a stored procedure for handling with uploaded files. This procedure, which based on the filename ( Fnnnn/<filename> ) , select the uploaded content through apex_application_files, the location apex saves the files. and procedure outputted the file as a blob, which then can be used to insert/update in youre table
    Hope this example code will help you:
    procedure upload_bestand( p_file_name in varchar2
    , p_file out nocopy blob
    , p_filetype out nocopy varchar2 )
    is
    -- Cursor voor bepalen bestand uit apex_application+files
    cursor c_file ( b_file_name in varchar2)
    is
    select aaf.filename
    , aaf.mime_type
    , aaf.blob_content
    from apex_application_files aaf
    where aaf.name = b_file_name
    r_file c_file%rowtype;
    begin
    open c_file ( b_file_name => p_file_name );
    fetch c_file into r_file;
    if c_file%notfound
    then
    -- Upload van bestand niet geslaagd
    close c_file;
    raise e_file_err;
    end if;
    close c_file;
    -- Geupload bestand uit temp_upload tabel verwijdern
    delete from apex_application_files
    where name = p_file_name
    commit;
    p_file := r_file.blob_content;
    p_filetype := r_file.mime_type;
    end upload_bestand;

  • Encoding problem after File Content Conversion

    Hi SAP gurus!
    we're about exporting debitor data via PI into CSV files. Therefore we use a mapping to an intermediate structure. In the receiver file adapter a file content conversion is done into the target CSV format.
    We have a lot of data with eastern europe characters. Right after the mapping, everything is fine. All characters are processed correctly. After the file content conversion, the files written on the target system contain "?" instead of the special characters.
    Does anybody have any hint to fix this problem? We already tried to change the "file.encoding" parameter, but hasn't helped.
    Thanks in advance for your support!
    Cheers,
    Matthias

    Hello Satish,
    thanks for your reply.
    First, I have to explain, that the sender side isn't done by file adapter but IDoc adapter. So I cannot change the encoding on sender side.
    Both on IDoc and file side, the data is ok. Only when inserting the file content converion, the files become corrupted.
    Without using the FCC, tjhe target files are stored as UTF-8. When using FCC the files are stored as ANSI. (I tested this by opening the files in notepad and performing "Save As")
    Do you have further ideas?
    Cheers,
    Matthias

  • How to escape newline character(nl) in file content conversion parameter?

    Hi Experts,
    How to escape newline character(nl) in file content conversion parameter?
    For example:
    field1field2field3
    field4field5field6
    Means Item is splitted in two lines.
    I want to SKIP new line character
    and to collect all SIX fields.
    What will be the file content conversion parameter?
    Thanks in Advance..........

    Hi,
    as far as i know there is nothing in the standard. But the question is why dont you combine at mapping the fields into only structure?
    Regards,
    Udo

  • How to add do not read file content option inside File Adapter (Synch Read)

    Hi,
    Is there any way, that I can skip reading the file content inside file adapter with operation as Synchronous Read ( I just want to read the file name and directory and if the file name matches with the input variables then I have to delete the files, for this i am using FA with synch read operation, everything is fine like deletion, but it is reading the file content and storing it in DB, i dont want this) .

    This will solve your problem.
    http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm#CHDHIEBI
    HTH.
    Puneet.

  • How to save file content in BLOB using ODI?

    We have unix server where the files are stored in a particular directory.
    I have to create one table in Oracle db which will have 2columns.
    One column will have filename & in another column i need to store file content(whatever that file has) which should be a BLOB type.
    There is no restriction on file type,it could be .txt,.xls,.jpg.
    Need help
    Edited by: user11090018 on Jun 9, 2010 4:24 AM
    Edited by: user11090018 on Jun 10, 2010 10:22 PM

    If you can give a detail explanation about your requirement then we may try to come up with a solution .....

  • Receiver file Content Conversion with Header line

    Hi,
    Here I am doing receiver file content conversion with header line.
    I am able to get the output file correct, when I open the file in notepad the header line and data appearing in the same line (not accepted).
    But when I tried to open the name file in internet explorer I can see the header line and data in two different lines (accepted).
    What should I do I want to see the same output in the notepad?
    Please help me out.
    Thanks in advance,
    Srikanth.

    You can use NameA.addHeaderLine.
    Specify whether the text file will have a header line with column names. The following values are permitted:
    0 u2013 No header line
    1 u2013 Header line with column names from the XML document
    2 u2013 As for 1, followed by a blank line
    3 u2013 Header line is stored as NameA.headerLine in the configuration and is applied
    4 u2013 As for 3, followed by a blank line
    The below weblinks will help you to know the other paramters.
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
    http://help.sap.com/saphelp_nwpi71/helpdata/en/44/686e687f2a6d12e10000000a1553f6/content.htm

  • Receiver File Content Conversion - Multiple Hier. Levels, Several Files

    you can create several files using single message execution.
    one source message structure and target multiple messgae types(0..1) occurance
    and same thing you can implement in your Interface mapping.
    1 -> Multiple Inbound interfaces
    your target final strcture would be with Header,lineitems.
    your JDBC->XI Intermedicate.
         XI Intermediate ->XI final (this final structure will create the your file)
    that way you can design your scenario.
    Regards,
    Venu.

    Hello Venu, thanks for answering,
    When you talk about intermediate structure you are referring to the approach I mentioned in the link above or to something that can be done using the same scenario structure I have right now?
    I am going I little bit deeper in my scenario just in case I havent been so clear in my first explanation:
    Lets suppose I have 3 stores: 1001,1002,1003
    For each store there are 2 items: 999,888
    So XI retrieves the information from the DB thru a stored procedure. This is the output:
    STORE--PLU
    1001--999
    1001--888
    1002--999
    1002--888
    1003--999
    1003--888
    Please note the information is coming in a flat structure. In the beginning I tried to separate it into several outputs (selects) as shown below but I relaized that was not possible to be handled by XI:
    STORE--PLU
    query 1
    1001--999
    1001--888
    query2
    1002--999
    1002--888
    query
    1003--999
    1003--888
    That would have been the best approach as I would have generated one single file for each message and thats it, but unfortunately, Xi does not work that way with MSSQL Queries. So I had to made something up based on the answers I got from the SDN experts (Link is below in first message). There was when I used context handling for generating the structures myself within one single message.
    In the scenario shown above I would have just needed to generate the following structure for creating messages from the source:
    Level1: Main Node
    Level 2: Header
    Level 2: Body
    But now, As I am forced to generate my 3 structures within 1 single message, I had to insert one more node to wrap header and body in per iteration (as a file would do):
    Level1: Main Node
    Level2: File
    Level3: Header
    Level3: Body
    And that is the problem I am asking help for, that allegedly, XI File Content conversion can just handle up to 2 levels.
    Thanks again for answering Venu.
    Regards.
    Edited by: Anibal Granado on May 12, 2010 11:34 PM

  • Problem in File content Convertion ?

    Hi experts,
    i have a probelm in file content convertion......iam geting flat file with tab delimiter so how to convert it?
    Name.filedSeperator   under this how to pass the vaule....please send docs on file content convertion.
    Note:helpfull answer will be rewarded.
    regards,
    phani

    Hi;
    Have a look
    help link for Receiver file adapter (FCC) - http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
    These are a collection of blogs on content conversion (both receiver and sender)
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2005/08/17/nab-the-tab-file-adapter
    /people/jeyakumar.muthu2/blog/2005/11/29/file-content-conversion-for-unequal-number-of-columns
    /people/shabarish.vijayakumar/blog/2006/02/27/content-conversion-the-key-field-problem
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    /people/arpit.seth/blog/2005/06/02/file-receiver-with-content-conversion
    Mudit

  • Streaming XML file content to a HTTPS servlet..

    Hi,
    I want to stream the contents of a XML file , which I have generated through XDK for PL/SQL, to a HTTPS address for a servlet.
    This HTTPS connections uses certifcates for user authentication. I have the certifcate on my local machine. Is there anyway of doing this through PL/SQL? Are there any packages available in Oracle 8.1.6 for this purpose? Can somebody tell me if there is a better way of doing this?
    Any help will be greatly appreciated.
    Thanks.

    After some additional trials I found a solution by calling the stored procedure in this way
    DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_STORED_PROC);
    DBPrepareSQL (hdbc, "usp_InsertReport");
    DBCreateParamInt (hstmt, "", DB_PARAM_RETURN_VALUE, -1);
    DBCreateParamChar (hstmt, "XMLCONTENT", DB_PARAM_INPUT, sz_Buffer, (int) strlen(sz_Buffer) + 1 );
    DBExecutePreparedSQL (hstmt);
    DBClosePreparedSQL (hstmt);
    DBGetParamInt (hstmt, 1, &s32_TestId);
    where sz_Buffer is my xml file content and s32_TestID the return value of the stored procdure (usp_InsertReport(@XMLCONTENT XML))
    Now I face the problem, that DBCreateParamChar limits the buffer size to 8000 Bytes.
    Any idea to by-pass this shortage??

Maybe you are looking for