How to store a text file in a hash table in C#?

I am fairly new to c#. I am creating a console application project for practice. I am supposed to create a program that reads a text file (it's a poem), store it in a hash table, have two different sorts, and unhash the table. I managed to get the poem read
by using streamwriter, but now I am not sure how to store it in a hash table. 
I'm not sure if I am doing this hash table correct, but I made my hash table like this to store the text file: 
      Hashtable hashtable = new Hashtable();
            hashtable[1] = (@"C:\\Documents\\Datastructures\\Input\\Poem");

Hi,
Hashtable in C# represents a collection of key/value pairs which maps keys to value. Any non-null object can be used as a key but a value can. We can retrieve  items from hashTable to provide the key . Both keys and values are Objects.
Here is a sample about Hashtable,
Hashtable weeks = new Hashtable();
weeks.Add("1", "SunDay");
weeks.Add("2", "MonDay");
weeks.Add("3", "TueDay");
weeks.Add("4", "WedDay");
weeks.Add("5", "ThuDay");
weeks.Add("6", "FriDay");
weeks.Add("7", "SatDay");
//Display a single Item
MessageBox.Show(weeks["5"].ToString());
//Search an Item
if (weeks.ContainsValue("TueDay"))
MessageBox.Show("Find");
else
MessageBox.Show("Not find");
//remove an Item
weeks.Remove("3");
//Display all key value pairs
foreach (DictionaryEntry day in weeks)
MessageBox.Show(day.Key + " - " + day.Value);
>>I managed to get the poem read by using streamwriter, but now I am not sure how to store it in a hash table
Hashtable hashtable = new Hashtable();
hashtable[1] = (@"C:\\Documents\\Datastructures\\Input\\Poem");
But follow your scenario above, you just store a string path to hashtable not a file.
About saving data to a file, you can use the following code.
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);
file.Close();
Best wishes!
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • How to store the flat file data into custom table?

    Hi,
    Iam working on inbound interface.Can any one tell me how to store the flat file data into custom table?what is the procedure?
    Regards,
    Sujan

    Hie
    u can use function
    F4_FILENAME
    to pick the file from front-end or location.
    then use function
    WS_UPLOAD
    to upload into
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'   "Function to pick file
        EXPORTING
          field_name = 'p_file'     "file
        IMPORTING
          file_name  = p_file.     "file
      CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
         filename                       = p_file1
        TABLES
          data_tab                      = it_line
    *then loop at it_line splitting it into the fields of your custom table.
    loop at it_line.
              split itline at ',' into
              itab-name
              itab-surname.
    endloop.
    then u can insert the values into yo table from the itab work area.
    regards
    Isaac Prince

  • How I store my sound file in my database table

    Dear friend
    i make a table for store sound file
    table is create .
    but now
    how i insert that file which is at 'c:\my document '
    to this table.
    i try following command but it has a error
    insert into sound values('c:\my document\abc.au');
    what i do for it
    please mail me as soon as on following id
    [email protected]
    ok bye

    Dear friend
    i make a table for store sound file
    table is create .
    but now
    how i insert that file which is at 'c:\my document '
    to this table.
    i try following command but it has a error
    insert into sound values('c:\my document\abc.au');
    what i do for it
    please mail me as soon as on following id
    [email protected]
    ok bye

  • How can I sync text files into iPhone?

    How can I sync text files into iPhone? like doc. txt. for reading or editing

    The native iPhone OS doesn't allow that. I think there are several solutions to this, some of which may be against the AT&T or Apple rules. One legitimate solution is The Missing Sync for iPhone by mark/space (http://www.markspace.com).
    Before I had an iPhone, I owned a copy of The Missing Sync for Windows Mobile. It was a pretty decent app. In my opinion, though, their app for the iPhone is NOT worth the price ($40 new, $25 for a cross-grade).
    Also, check the App Store (if you have 2.0 software)--there may be an app that does this, probably for a lot less $.

  • How to upload a text file from a shared folder and provide an o/p

    how to upload a text file from a shared folder and provide an o/p  containing the details in each order in the text file

    Hi,
    Use <b>GUI_UPLOAD</b> to upload a text file from a shared folder.
    Use <b>GUI_DOWNLOAD</b> to download data in a file on the presentation server or use <b>OPEN DATASET, TRANSFER</b> and <b>CLOSE DATASET</b> statements to download data to the application server.
    Now, I hope the code for data fetching, if required, is already present in the report.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • How to convert a text file in lower case to upper case?

    I've a beginner in java world and I just come through the tutorial in http://java.sun.com/docs/books/tutorial/essential/io/filestreams.html showing how to copy a text file:
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("farrago.txt");
         File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    And I would like to ask how to covert all lower case letters in input file to upper case letter in output file at the same time of copying.
    I guess it'll be using Character.toUpperCase(c), but I don't know how to do it actually.
    Any help would be much appreciated.

    Hope this helps
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
    File inputFile = new File("farrago.txt");
    File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    BufferedReader buff = new BufferedReader(in);
    String c;
    while ((c = buff.readLine()) != null)
    out.write(c.toUpperCase());
    in.close();
    out.close();
    }

  • How to read several text files at a time

    Dear all
          Read and write one text file is not a problem, but  what confusies me is how to read several text files at one time, in the meanwhile,
    is it possible to display the name of the text file?
    For example, assuming I want to load file" cha 1, cha 2 , cha 3, " at one time and show their names, how to hadle with it
    I have reviewed some files and it is not helpful

    Either with a 'for' loop like in the lib you have attached, or like this attached VI
    that's it
    Message Edited by devchander on 05-30-2006 05:11 AM
    Attachments:
    MULTIPLE READ.vi ‏44 KB

  • How to send a text file to a printer?

    Hi, I'm in dark on how to send a text file to a printer through Java Stored Procedure.
    Here are what I tried so far (OS: win 2000, Oracle: 817 or 9i2):
    1, Enable DOS command in Java Stored Proc. and try to send PRINT command there:
    public static String Run(String Command){
    try{
    Runtime.getRuntime().exec(Command);
    System.out.println("Command: " + Command);
    return("0");
    catch (Exception e){
    System.out.println("Error running command: " + Command +
    "\n" + e.getMessage());
    return(e.getMessage());
    public static void main(String args[]){
    if (args.length == 1)
    Run("print /D:\\\\enterprise\\john " + args[0]);
    else System.out.println("Usage: java OSCommand filename");
    PL/SQL wrapper:
    CREATE OR REPLACE FUNCTION OSCommand_Run(p1 IN VARCHAR2) RETURN VARCHAR2 AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'OSCommand.Run(java.lang.String) return java.lang.String';
    SQL command:
    //print /D:\\machine\printer test.txt
    I loaded the Java Stored Procedure into SYSDBS account, it failed silently, even though piece of code works fine in external JVM.
    2, Use filePrinter:
    public static String print(String printString) {
    try{
    String printerUNC = "\\\\machine\\printer";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    return "OK";
    }catch(Exception e){
    e.printStackTrace();
    return "Exception: " + e.getMessage();
    public static void main(String[] args) {
    try{
    String printerUNC = "\\\\machine\\printer";
    String printString = "Hello World";
    FileWriter fw = new FileWriter(printerUNC);
    PrintWriter pw = new PrintWriter(fw);
    pw.println(printString);
    fw.close();
    }catch(Exception e){e.printStackTrace();}
    I loaded it into SYSDBS too, and tried with this:
    SQL> select MY_PRINT.PRINT('HELLO from Oracle') from dual;
    MY_PRINT.PRINT('HELLOFROMORACLE')
    Exception: No such file or directory
    SQL> show user
    USER is "SYS"
    It works in external JVM too.
    What's wrong with this?
    Thanks for any help in advance,
    Charles

    Avi:
    Thanks for your response!
    I put the java code in SYS, 'cause I assume that account has max privilege. If the test is successful, I will move that to some user schema and then to deal with those privilege settings... But I'm unlucky.
    I checked Ask Tom, this is what I got from http://asktom.oracle.com/pls/ask/f?p=4950:8:1619723::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:38012348052,%7Bprinter%7D:
    ... Print file from PL/SQL ...
    If you are using Oracle8i, release 8.1 -- much can be done with Java. java
    would be able to print directly from the server.
    Looks like using Java to print out file is better than PL/SQL. But there's no more hint there! And, no new question can be asked there today either...
    I'm wondering whether we can create a socket to a printer and send the characters there directly... Anyone has experience on this?
    Thanks for all the help in advance,
    Charles

  • How to zip a text file and send as email attachment in SAP version 4.6c?

    Hi Guru,
    How to zip a text file in SAP version 4.6c which doesn't have class CL_ABAP_ZIP?
    Please help.
    Thanks & Regards,
    Ari

    Hi,
    Try this link
    [http://sap.ittoolbox.com/groups/technical-functional/sap-dev/sapr3dev-zip-file-from-sap-1707099?cv=expanded]
    Cheers,
    Surinder

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • Data from itab to be store in text file in desktop

    hi
    i am tyring to store the data from itab into a text file in desktop,but its now owrking.
    i am using open dataset statment,but no where data is storing.My code:
    TYPES : BEGIN OF ST_DEMO,
    REG_NO(10) TYPE C,
    NAME(20)   TYPE C,
    ADDR(20)   TYPE C,
    END OF ST_DEMO.
    DATA : WA_DEMO TYPE ST_DEMO,
    IT_DEMO TYPE TABLE OF ST_DEMO,
    L_FNAME TYPE dxfile-filename .
    PARAMETERS: P_FNAME(128) TYPE C DEFAULT '\usr\sap\put\vipin.txt' OBLIGATORY.
    L_FNAME = P_FNAME.
    WA_DEMO-REG_NO = '100001'.
    WA_DEMO-NAME = 'ANAND'.
    WA_DEMO-ADDR = 'NAGARKOVIL'.
    APPEND WA_DEMO TO IT_DEMO.
    OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    WRITE :5 'REG NUM',16 'NAME',37 'ADDRESS' .
    LOOP AT IT_DEMO INTO WA_DEMO.
      IF SY-SUBRC = 0.
        TRANSFER WA_DEMO TO L_FNAME.
        WRITE :/5 WA_DEMO-REG_NO,16 WA_DEMO-NAME,37 WA_DEMO-ADDR.
      ENDIF.
    ENDLOOP.
    close DATASET L_FNAME.
    please tell me where is the prob?I wan to schedule it for background job.
    regds
    vipin

    hi
    here is the code for :  "data from itab to be store in text file in desktop"
    TABLES: vbak.    " standard table
    *                           Type Pools                                 *
    TYPE-POOLS: slis.
    *                     Global Structure Definitions                     *
    *-- Structure to hold data from table CE1MCK2
    TYPES: BEGIN OF tp_itab1,
           vbeln LIKE vbap-vbeln,
           posnr LIKE vbap-posnr,
           werks LIKE vbap-werks,
           lgort LIKE vbap-lgort,
           END OF tp_itab1.
    *-- Data Declaration
    DATA: t_itab1 TYPE TABLE OF tp_itab1.
    DATA : i_fieldcat TYPE slis_t_fieldcat_alv.
    *                    Selection  Screen                                 *
    *--Sales document-block
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
    SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
    SELECTION-SCREEN END OF  BLOCK b1.
    *--Display option - block
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
    PARAMETERS: alv_list RADIOBUTTON GROUP g1,
                alv_grid RADIOBUTTON GROUP g1.
    SELECTION-SCREEN END OF  BLOCK b2.
    *file download - block
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t03.
    PARAMETERS: topc AS CHECKBOX,
                p_file TYPE rlgrap-filename.
    SELECTION-SCREEN END OF  BLOCK b3.
    *                      Initialization.                                *
    *                      At Selection Screen                            *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
        EXPORTING
          dynpfield_filename = 'P_FILE'
          dyname             = sy-cprog
          dynumb             = sy-dynnr
          filetype           = 'P'      "P-->Physical
          location           = 'P'     "P Presentation Srever
          server             = space.
    AT SELECTION-SCREEN ON s_vbeln.
      PERFORM vbeln_validate.
    *                           Start Of Selection                         *
    START-OF-SELECTION.
    *-- Fetching all the required data into the internal table
      PERFORM select_data.
    *                           End Of Selection                           *
    END-OF-SELECTION.
      IF t_itab1[] IS NOT INITIAL.
        IF topc IS NOT INITIAL.
          PERFORM download.
          MESSAGE 'Data Download Completed' TYPE 'S'.
        ENDIF.
        PERFORM display.
      ELSE.
        MESSAGE 'No Records Found' TYPE 'I'.
      ENDIF.
    *                           Top Of Page Event                          *
    TOP-OF-PAGE.
    *& Form           :      select_data
    * Description     : Fetching all the data into the internal tables
    *  parameters    :  none
    FORM select_data .
      SELECT vbeln
         posnr
         werks
         lgort
         INTO CORRESPONDING  FIELDS OF TABLE t_itab1
         FROM vbap
         WHERE  vbeln IN s_vbeln.
      IF sy-subrc <> 0.
        MESSAGE 'Enter The Valid Sales Document Number'(t04) TYPE 'I'.
        EXIT.
      ENDIF.
    ENDFORM.                    " select_data
    *& Form        : display
    *  decription  : to display data in given format
    * parameters   :  none
    FORM display .
      IF alv_list = 'X'.
        PERFORM build_fieldcat TABLES i_fieldcat[]
                               USING :
    *-Output-field Table      Len  Ref fld Ref tab Heading    Col_pos
       'VBELN'       'T_ITAB1'     10   'VBAP'  'VBELN'    ''            1,
       'POSNR'       'T_ITAB1'     6    'VBAP'  'POSNR'    ''            2,
       'WERKS'       'T_ITAB1'     4    'VBAP'  'WERKS'    ''            3,
       'LGORT'       'T_ITAB1'     4    'VBAP'  'LGORT'    ''            4.
        CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
          EXPORTING
            i_callback_program       = sy-repid
    *        i_callback_pf_status_set = c_pf_status
            i_callback_user_command  = 'USER_COMMAND '
    *        it_events                = t_alv_events[]
            it_fieldcat              = i_fieldcat[]
          TABLES
            t_outtab                 = t_itab1[]
          EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDIF.
      IF alv_grid = 'X'.
        PERFORM build_fieldcat TABLES i_fieldcat[]
                                 USING :
    *-Output-field Table      Len  Ref fld Ref tab Heading    Col_pos
         'VBELN'       'T_ITAB1'     10   'VBAP'  'VBELN'    ''            1,
         'POSNR'       'T_ITAB1'     6    'VBAP'  'POSNR'    ''            2,
         'WERKS'       'T_ITAB1'     4    'VBAP'  'WERKS'    ''            3,
         'LGORT'       'T_ITAB1'     4    'VBAP'  'LGORT'    ''            4.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program       = sy-repid
    *        i_callback_pf_status_set = c_pf_status
            i_callback_user_command  = 'USER_COMMAND '
            it_fieldcat              = i_fieldcat
          TABLES
            t_outtab                 = t_itab1[]
        EXCEPTIONS
       program_error                     = 1
       OTHERS                            = 2.
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDIF.
    ENDFORM.                    " display
    *& Form        : vbeln_validate
    *  description : to validate sales document number
    * parameters   :  none
    FORM vbeln_validate .
      DATA: l_vbeln TYPE vbak-vbeln.
      SELECT SINGLE vbeln
        FROM vbak
        INTO l_vbeln
        WHERE vbeln IN s_vbeln.
      IF sy-subrc NE 0.
        MESSAGE 'ENTER THE VALID SALES DOCUMENT NO:' TYPE 'I'.
        EXIT.
      ENDIF.
    ENDFORM.                    " vbeln_validate
    *& Form       :build_fieldcat
    * Description : This routine fills field-catalogue
    *  Prameters  : none
    FORM build_fieldcat TABLES  fpt_fieldcat TYPE slis_t_fieldcat_alv
                        USING   fp_field     TYPE slis_fieldname
                                fp_table     TYPE slis_tabname
                                fp_length    TYPE dd03p-outputlen
                                fp_ref_tab   TYPE dd03p-tabname
                                fp_ref_fld   TYPE dd03p-fieldname
                                fp_seltext   TYPE dd03p-scrtext_l
                                fp_col_pos   TYPE sy-cucol.
    *-- Local data declaration
      DATA:   wl_fieldcat TYPE slis_fieldcat_alv.
    *-- Clear WorkArea
      wl_fieldcat-fieldname       = fp_field.
      wl_fieldcat-tabname         = fp_table.
      wl_fieldcat-outputlen       = fp_length.
      wl_fieldcat-ref_tabname     = fp_ref_tab.
      wl_fieldcat-ref_fieldname   = fp_ref_fld.
      wl_fieldcat-seltext_l       = fp_seltext.
      wl_fieldcat-col_pos         = fp_col_pos.
    *-- Update Field Catalog Table
      APPEND wl_fieldcat  TO  fpt_fieldcat.
    ENDFORM.                    "build_fieldcat
    *& Form        : download
    *  description : To Download The Data
    *  Parameters  :  none
    FORM download .
      DATA: l_file TYPE string.
      l_file = p_file.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = l_file
          filetype                = 'ASC'
        TABLES
          data_tab                = t_itab1
        EXCEPTIONS
          file_write_error        = 1
          no_batch                = 2
          gui_refuse_filetransfer = 3
          invalid_type            = 4
          no_authority            = 5
          unknown_error           = 6.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " download
    hope it will help you
    regards
    rahul

  • "how to load a text file to oracle table"

    hi to all
    can anybody help me "how to load a text file to oracle table", this is first time i am doing, plz give me steps.
    Regards
    MKhaleel

    Usage: SQLLOAD keyword=value [,keyword=value,...]
    Valid Keywords:
    userid -- ORACLE username/password
    control -- Control file name
    log -- Log file name
    bad -- Bad file name
    data -- Data file name
    discard -- Discard file name
    discardmax -- Number of discards to allow (Default all)
    skip -- Number of logical records to skip (Default 0)
    load -- Number of logical records to load (Default all)
    errors -- Number of errors to allow (Default 50)
    rows -- Number of rows in conventional path bind array or between direct path data saves (Default: Conventional path 64, Direct path all)
    bindsize -- Size of conventional path bind array in bytes (Default 256000)
    silent -- Suppress messages during run (header, feedback, errors, discards, partitions)
    direct -- use direct path (Default FALSE)
    parfile -- parameter file: name of file that contains parameter specifications
    parallel -- do parallel load (Default FALSE)
    file -- File to allocate extents from
    skip_unusable_indexes -- disallow/allow unusable indexes or index partitions (Default FALSE)
    skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable (Default FALSE)
    commit_discontinued -- commit loaded rows when load is discontinued (Default FALSE)
    readsize -- Size of Read buffer (Default 1048576)
    external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE
    (Default NOT_USED)
    columnarrayrows -- Number of rows for direct path column array (Default 5000)
    streamsize -- Size of direct path stream buffer in bytes (Default 256000)
    multithreading -- use multithreading in direct path
    resumable -- enable or disable resumable for current session (Default FALSE)
    resumable_name -- text string to help identify resumable statement
    resumable_timeout -- wait time (in seconds) for RESUMABLE (Default 7200)
    PLEASE NOTE: Command-line parameters may be specified either by position or by keywords. An example of the former case is 'sqlldr scott/tiger foo'; an example of the latter is 'sqlldr control=foo userid=scott/tiger'. One may specify parameters by position before but not after parameters specified by keywords. For example, 'sqlldr scott/tiger control=foo logfile=log' is allowed, but 'sqlldr scott/tiger control=foo log' is not, even though the position of the parameter 'log' is correct.
    SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\PFS2004.CTL LOG=D:\PFS2004.LOG BAD=D:\PFS2004.BAD DATA=D:\PFS2004.CSV
    SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\CLAB2004.CTL LOG=D:\CLAB2004.LOG BAD=D:\CLAB2004.BAD DATA=D:\CLAB2004.CSV
    SQLLDR USERID=GROWSTAR/[email protected] CONTROL=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.CTL LOG=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.LOG BAD=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.BAD DATA=D:\GROW\DEACTIVATESTAFF\DEACTIVATESTAFF.CSV

  • How to attach a text file as an attachment to email message?

    Hello Everybody,
    I have a .csv file, in which details about emp-id, emp-name, e-expenses for Reimbursement and email address are stored.
    My application reads this .csv file, and sends a mail to each employee with his id, salary details in text format. (by changing content type to "text/plain") The code is working fine. But,
    My problem is:
    The message is sent as message body to the end user.
    The end user / the person who receives this mail will not be a technical person. So,
    1) If he trys to take a print out of this e-mail, He get only half of it.(as no. of colums will be more than paper size).
    2) I am finding alignment problem. IF employee name is too big, other columns will shift to right and data will not be exactly under column header. (it is going in zig zag way)
    So, I thought sending text file with all the details as an attachment might do well.
    But, I don't know how to attach a text file to email-message body.
    code
    try
                   {               String s1="";
                                  File f1 = new File(the path);
                                  FileInputStream fstream = new FileInputStream(f1); //new
                                  BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
                                  int count=0;
                                  while((s1=br.readLine())!=null )
                                                 count++;
                                                 //out.println("within while loop "+count);
                                                 StringTokenizer st = new StringTokenizer(s1,",");
                                                 if ((st.hasMoreTokens())&&(count>1))
                                            String a=st.nextToken().trim();
                                                 String b=st.nextToken();
                                                 String c=st.nextToken();
                                                 String d=st.nextToken();
                                                 String e=st.nextToken();
                                                 String f=st.nextToken();
                                                 String g=st.nextToken();
                                                 String h=st.nextToken();
                                                 String i=st.nextToken();
                                                 String j=st.nextToken();
                                                 String k=st.nextToken();
                                                 String l=st.nextToken();
                                                 String m=st.nextToken();
                                                 String n=st.nextToken();
                                                 String o=st.nextToken();
                                                 String p=st.nextToken();
                                                 String q=st.nextToken();
                                                 String mail=st.nextToken();
                                                 String s=st.nextToken();
                                                 //out.println("b="+b+"c="+c+"d="+d+"e="+e+"f="+f+"mail="+mail);
                                                 %>
    <%
                                            String to =mail;
                                                 String from =request.getParameter("fromadd");                                        
                                                 String subject ="Statement of Expenses";
                                                 String smtp ="mail.xxxxxxxxxx.com";
                                                 String message="";                                        
                                                 message=message.concat("EMP ID");
                                                 message=message.concat("     ");
                                                 message=message.concat("Name");
                                                 message=message.concat("          ");
                                                 message=message.concat("Dept No.");
                                                 message=message.concat("     ");
                                                 message=message.concat("Acc No.");
                                                 message=message.concat("     ");
                                                 message=message.concat("*****************************************************************************************");     
                                                 message=message.concat(a);
                                                 message=message.concat("     ");
                                                 message=message.concat(b);
                                                 message=message.concat("          ");
                                                 message=message.concat(c);
                                                 message=message.concat("     ");
                                                 message=message.concat(d);
                                                 Properties props = System.getProperties();
                                                 // Puts the SMTP server name to properties object
                                                 props.put("mail.smtp.host", smtp);
                                                 // Get the default Session using Properties Object
                                                 Session session1 = Session.getDefaultInstance(props, null);
                                                 // Create a New message
                                                 MimeMessage msg = new MimeMessage(session1);
                                                 // Set the From address
                                                 msg.setFrom(new InternetAddress(from));
                                                 // Setting the "To recipients" addresses
                                            msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
                                            /* // Setting the "cc recipients" addresses
                                            msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc, false));
                                            // Setting the "Bcc recipients" addresses
                                            msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc, false)); */
                                            // Sets the Subject
                                            msg.setSubject(subject);
                                            // set the meaasge in HTML format
                                            msg.setContent(message,"text/plain");
                                            // Set the Date: header
                                            msg.setSentDate(new java.util.Date());
                                            // Send the message
                                            Transport.send(msg);
                                            // Display Success message
                                            result =result.concat("<tr><td>"+b+"</td>"+"<td>"+to+"</td></tr>");
                                                      }//end of if of hasmore element
                                       }// end of while loop
                        out.println(result);                    
    }catch(Exception e)
                        // If here, then error in sending Mail. Display Error message.
                        result="Unable to send your message";
                        out.println("e="+e);
    Any help will be appreciated.
    Thanks and regards.
    Ashvini

    <html>
    <p>
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText("Your Messages");
    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource("Your Attachments");
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    msg.setContent(mp);
    msg.saveChanges();
    msg.writeTo(System.out);
    msg.setSubject(subject);
    Transport.send(msg);
    </p>
    <B><U>See you can add above code in your program and see the magic</U></B>
    Bye
    regards--
    Ashish
    </html>

  • How to read a text file using Java

    Guys,
    Good day!
    Please help me how to read a text file using Java and create/convert that text file into XML.
    Thanks and God Bless.
    Regards,
    I-Talk

         public void fileRead(){
                 File aFile =new File("myFile.txt");
             BufferedReader input = null;
             try {
               input = new BufferedReader( new FileReader(aFile) );
               String line = null;
               while (( line = input.readLine()) != null){
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
         }This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
    cheers
    Mohammed Jubaer Arif.

  • How can I read text files from LAN if I only know the hostname?

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    <p>1. How can I read text files from LAN if I only know the hostname, or IP address?
    <p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
    (ex. how can I read the 120th line?)
    <p>Please help!
    <p>sorry for the bad english

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
    The hostname is server, not file.
    2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
    (ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is

Maybe you are looking for

  • How is iMessage used on iPad and iPhone?

    I have set up iMessage on my iPad and iPhone, but still don't know how it is used.  I tried sending a message, but after entering the contact of the person, send doesn't seem to be highlighted.  What could be the problem?

  • Satellite A130: Fn key not working with Vista - only FlashCards

    Hi, I have been looking around in the forums but I couldn't find solutions to my problem. I have a satelite A130 and I am running a windows VISTA home basic. I have a problem with my fn functions. I can only use the flash cards on top of my screen, j

  • Bookmarks in a PDF Portfolio

    How can I create bookmarks in a PDF Folio. I have a sample of one so I know it can be done but have no idea how to go about it. Any suggestions would ve very welcome.

  • Problem evaluating boolean in XSLT

    Hi, I am running into a wierd problem. I have a small BPEL process with input schema as shown below. <element name="testIssuesProcessRequest"> <complexType> <sequence> <element name="boolValue" type="boolean"/> <element name="dateValue" type="date"/>

  • Setting a buttons color

    I have been trying to change the color of a flex button to blue. If the canvas background is white, my button blends with the white. What property can I set to stop this. All I want is a solid blue button without having the background blend into it.