Trying to Read In Values Into Hash

I am reading in a file...and i have this file being read
Fileds:Name|Address|SS
john|billsbury drive|030303030
how do i make a hash table so that when my tokener reads Name, it could store john so that it would be
Name = John
Address = billsbuy drive
etc.
You will see that i am using an array to get the different names of fields, but this is not gonna work because I never know how big my array really is. So please help.
here is my code wher e i read in my info from file.
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.Date;
import java.lang.*;
public class file {
public static void main(String[] args)
// Display today's date using a default fomat for the current locale
DateFormat defaultDate = DateFormat.getDateInstance();
System.out.println(defaultDate.format(new Date()));
// Display Current time using a short time format for the current locale
DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.SHORT);
System.out.println(shortTime.format(new Date()));
// Display date and time using a long format for both
DateFormat longTimestamp = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
System.out.println(longTimestamp.format(new Date()));
// Declare Variables
StringBuffer desc;
BufferedReader in = null;
// Keep looking through the file while it is still not end of file
try
// Opens the file and reads it
File theFile = new File("23133202.2");
in = new BufferedReader(new FileReader(theFile));
// Get Length of File, and see how big it is
long filelength = theFile.length();
Date lastModified = new java.util.Date(theFile.lastModified());
String str = new String("");
char ch = (char)179;
int i=0, x, y, a, b, c, d;
int fromIndex = 0;
String name;
int fieldCount = 0;
// Read the file line by line using a Token
while((str = in.readLine()) != null){
StringTokenizer st = new StringTokenizer(str,":");
int count = st.countTokens();
String[] dataField = new String[1000];
// tokener contains all the field variables
String tokener = new String("");
while(st.hasMoreTokens())
tokener = st.nextToken();
//System.out.println(tokener);
//System.out.println(str);
// Get Group Names, and Start Inserting Data Into Database
if (str.indexOf("Group") != -1) {
tokener = st.nextToken();
x = tokener.indexOf("\u00B3");
name = tokener;
// y = tokener.indexOf("IDNR");
// a = tokener.indexOf("LASTNAME");
// b = tokener.indexOf("UNIQID");
// c = tokener.indexOf("EXAMFILE");
System.out.println(x);
System.out.println("I want" + " " + name);
// System.out.println(y);
} else if (str.indexOf("Fields") != -1) {
tokener = st.nextToken();
System.out.println("SOMETHING NEW");
StringTokenizer tk = new StringTokenizer(str,"\u00B3");
String tok = new String("");
while(tk.hasMoreTokens()) {
tok = tk.nextToken();
dataField[fieldCount] = tok;
System.out.println("IN BABY" + " " + dataField[fieldCount]);
fieldCount ++;
} else {
System.out.println("Not What I want" + " " + tokener);
} // end the main while
in.close();
// end try
catch (Exception e)
try {
in.close();
catch (Exception ignore) { }
e.printStackTrace();
// end catch...in.close();

By decyphering your code again, I relialised that the first field is present in your file, so, here is your code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.text.DateFormat;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Hashtable;
public class file {
    public static void main(String[] args) {
// Display today's date using a default fomat for the current locale
        DateFormat defaultDate = DateFormat.getDateInstance();
        System.out.println(defaultDate.format(new Date()));
// Display Current time using a short time format for the current locale
        DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.SHORT);
        System.out.println(shortTime.format(new Date()));
// Display date and time using a long format for both
        DateFormat longTimestamp = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
        System.out.println(longTimestamp.format(new Date()));
// Declare Variables
        StringBuffer desc;
        BufferedReader in = null;
// Keep looking through the file while it is still not end of file
        try {
// Opens the file and reads it
            File theFile = new File("23133202.2");
            in = new BufferedReader(new FileReader(theFile));
            String keyLine = in.readLine(); // Get Keys
            String valueLine = in.readLine(); // Get values
            StringTokenizer keys = new StringTokenizer(keyLine, ":|");
            keys.nextToken(); // Ignore the 'fields:' entry
            StringTokenizer values = new StringTokenizer(valueLine, "|");
            Hashtable yourHashtable = new Hashtable();
            while (keys.hasMoreTokens()) {
                String key = keys.nextToken();
                String value = values.nextToken();
                yourHashtable.put(key, value);
            System.out.println("yourHashtable = " + yourHashtable);
// end try
        catch (Exception e) {
            e.printStackTrace();
        finally {
            try {
                in.close();
            } catch (Exception ignore) {
// end catch...in.close();
}The output this produced is:
06-Nov-01
20:30
06 November 2001 20:30:06 o'clock GMT
yourHashtable = {Name=john, SS=030303030, Address=billsbury drive}
HTH,
Manuel Amago.

Similar Messages

  • How to read RGB values into Set

    Hi,
    I have been told that to count the total number of unique colors in an image is by reading each pixel RGB values into a set.
    I have checked this and it is true that the set can do this fine if considering only either one channel of the R,G or B (this does not allow me to know the exact number of color exist). However, I am confuse on how to have all three R, G and B values into a set so that the set can consider the whole 3 values of RG and B as a color which can then be differentiated separately.
    I think pixelgrabber allow to getPixel RGB values but I am working with JIU getsample method. Perhaps I missed out other methods in JIU which have the same functionality as in pixelGrabber.
    I am working on an image analysis so I need to figure out this out first.
    I am hoping anyone can help me out with this and I thank you.

    as mentioned, pack the rgb values into an integer.
    instead of a set, you will get better performance and
    memory useage using a sorted, dynamically allocated
    int array. With some minor work, you better this
    structure by using more than one sorted array and a
    cheap rgb mask hashing mechanism. I don't know what
    JIU is, but look at the source of java.awt.Color for
    details on how to pack/unpack rgb values.Hi,
    Thank for your feedback. I have tried to pack the rgb values into an integer. At the moment I just making used of Set (will look into probably ArrayList after I get the rgb values correct). However, I am not sure whether my code is correct (which I doubt) or not. Not sure how the output looks like that. If you could have a look at it and confirm me, I would be very much thanking you.
    the code snippet:
    public void countColour() {
    int r, g, b;
    int[] rgb1DArray = new int[h * w];
    int[] rgb = new int[4];
    Set set = new HashSet();
    int alpha = 255;
    for (int i = 0, cnt = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
    r = intImg.getSample(0, i, j);
    g = intImg.getSample(1, i, j);
    b = intImg.getSample(2, i, j);
    System.out.println(r+ "," g "," +b); // just checking rgb values
    //rgb[0] = alpha;
    rgb[1] = r;
    rgb[2] = g;
    rgb[3] = b;
    System.out.println(rgb[0]+ "," rgb[1] "," rgb[2] "," +rgb[3]);
    rgb1DArray[cnt] = ((rgb[1])<<16)|
    ((rgb[2]<<8))|(rgb[3]);
    System.out.println("rgb["+cnt+"] :" +rgb1DArray[cnt]);
    output:
    Image file size is 230 x 236
    204,221,203
    0,204,221,203
    rgb[0] :13426123
    204,212,191
    0,204,212,191
    rgb[1] :13423807
    180,166,140
    0,180,166,140
    rgb[2] :11839116
    236,209,166
    0,236,209,166
    rgb[3] :15520166

  • Reading Timestamp value into an SSIS variable

    I need to read the last timestamp value (MAX(TimeStampValue)) from a table, store it in a variable in SSIS and using the variable, perform a comparison against another table and load delta records. 
    The string data type is not playing well with the timestamp data type and things get even more complicated if I try to store the timestamp value as a varchar in a table.
    Is there any variable data types in SSIS that will store the timestamp value easier than a string?

    It could be due to the time stamp value being incompatible with the date time functions which you need to fix.
    So to make it conform manipulate on its value to get the proper format.
    PS: Varchar WILL swallow any text, please be more specific, think how others would be reproducing YOUR issue.
    Arthur My Blog

  • Reading a value into a variable

    How can I fill a variable with an integer from the keyboard??
    Using the codeline
    var = (int)System.in.read; System.in.read;System.in.read;
    I don�t get the number but the aschii code for the character.
    Why??
    DEADOC

    You get the ascii code because thats what System.in reads.
    Read a string and then parse it into an int
    StringBuffer sb = new StringBuffer();
    int i;
    while ((i = System.in.read()) != 10 && i != 13) { // read until you hit enter
      sb.append((char)i);
    String s = sb.toString(); // the string you entered
    int var = Integer.parseInt(s); // will throw an exception if the string cannot be parsed to an int
    System.out.println("You entered: "+var); // print the integer value

  • Short dump in reading selection values in Report

    Hi all,
    I have created a Navegational Attributte and added this Info Object in the existing Query and for this object we have created Charactistics Value Variable with Uesr Entry.
    But, When we use input selection option to select a vlaue for this Variable  in the Variable Selection Screen it is trying to read the values and going into short Dump but for other variables Selection option is working fine.
    Please anyone help me if you have the solution.
    Regards,
    Ali.

    Hi,
       Try deleting the master data and reload the master data again and check for the selection variables. Check the short dump in ST22 it will say which master table ie SID table or master table where the join fails.
    Thanks,
    Arun

  • Insert value into a column based on value of another column

    Hi,
    I am trying to insert a value into a record based on a column in
    the record, using a trigger. The complication arises because
    the new value is selected from the same table. For example:
    SELECT COL1, COL2, COL3, COL4 from TABLE1
    I want to set COL2 and COL3 based on the value of COL4. And to
    get the value of COL2 and COL3, I will go back to TABLE1 and set
    the condition to TABLE1.COL1 = :NEW.COL4
    I cannot seem to execute the trigger as I get the message "ORA-
    04091: table SYSTEM.TABLE1 is mutating, trigger/function may not
    see it" everytime.
    Is this the correct way to achieve what I wanted? Or is there
    another way?
    Appreciate your feedback. Thank you in advance.

    Hi,
    I am trying to insert a value into a record based on a column in
    the record, using a trigger. The complication arises because
    the new value is selected from the same table. For example:
    SELECT COL1, COL2, COL3, COL4 from TABLE1
    I want to set COL2 and COL3 based on the value of COL4. And to
    get the value of COL2 and COL3, I will go back to TABLE1 and set
    the condition to TABLE1.COL1 = :NEW.COL4
    I cannot seem to execute the trigger as I get the message "ORA-
    04091: table SYSTEM.TABLE1 is mutating, trigger/function may not
    see it" everytime.
    Is this the correct way to achieve what I wanted? Or is there
    another way?
    Appreciate your feedback. Thank you in advance. I'm not sure what you mean when you insert a value into a
    record, but if you are setting a value in a column of the same
    record using a trigger, then it's easy.
    :new.COL2 := ....:new.COL4...
    :new.COL3 := ....:new.COL4...
    The trigger must be 'INSERT or UPDATE' and 'FOR EACH RECORD'.
    If you are setting a different record in the same table, the
    solution is much more difficult.

  • Retriving values into a variable

    hi,
    I'm novice to calcscripts...
    i have declared one variable within a fix cmd.
    I want to retrieve data into this variable combination whatever mentioned in the fix cmd some members also need prior.
    var LyBase;
    LyBase=@Prior(FY11,Base);
    i'm getting error-1200329:ivalid assignment of base
    i want to know
    "LyBase"="Can i give member combination here to retrieve data into this variable";

    variables need to be used in a calc block, here are some examples as it has been covered in the past
    Re: Temporary Variable Issue: Invalid Member Name
    Re: Using variables in Calc scripts and Business Rules
    Cheers
    John
    http://john-goodwin.blogspot.com/
    Hi john,
    thanks for ur reply,i have declared the variable inside the fix cmd,but when i'm trying to retrieve a value into this variable it is throwing error,
    *Error: 1012038 The constant [FY10->Actuals->Locked->Base] assigned to variable [LyBase] is not a number*.
    calc script is as follows
    fix(my sparse dim mbrs)
    var LyBase;
    LyBase=FY10->Actuals->Locked->Base;
    when executing this script i'm getting the above error.how can i fix it?

  • How to import column values into SharePoint 2013 Term Store Using Powershell(CSOM)

    Hi, 
    I do have SharePoint 2013 list with more than 500 items in it.Now I am trying to import column values into SharePoint 2013 Term Set A using Powershell scripts.
    I am new to Powershell(csom) and can anybody help me out to accomplish this task?
    Any help would be greately appreciated.
    Thank you,
    AA.
    AA.

    Hi
    check this doc
    http://wellytonian.com/2012/10/sharepoint-2010-2013-term-store-importer-using-csv/
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • Read variable value knowing only name

    Is there a way to read a variable value from only knowing the label name? I have Labview 11 and am reading a text file with a list of variable labels and trying to read the value without having to create a case structure of hundreds of variables.
    Solved!
    Go to Solution.

    My first answer was going to be "No", but then I started to think about it.  I'm assuming that the Variables are controls or indicators that are part of the VI or Project of interest.  You could do the following (but it could get messy) --
    Use the AllVIs property of the current Application to get an array of all VI names in memory.
    For each VI name, get a VI Reference, use that to get a Front Panel Reference (property), use that to get Controls[] (property).
    For each Control, get its Label (property).  At this point, I think I'd make two arrays, one of the Control References, the other of the Labels.
    Once your arrays are built, you can use the Array functions to find the index of the variable you want in the Labels array, and use that index to pull the Value out using the appropriate indexed Control Reference.  Note that this doesn't tell you the "Type" of the variable -- this will be left as an Exercise to the Reader.
    Let me know if this works, and is worth the effort.
    BS

  • Reading any value from table into a string (Especially date etc..)

    How would I read any value from a table into a string?
    Currently doing the following...
    data ret_val type string.
    select single (wa_map-qes_field) from z_qekko into ret_val
    where
    angnr = _angnr.
    When the source field is a date it bombs though.
    The result goes into a BDCDATA-fval.
    regards
    Dylan.

    Tried...
    1    DATA: lp_data TYPE REF TO DATA.
    2    FIELD-SYMBOLS: <value> TYPE ANY.
    3    CREATE DATA lp_data LIKE (wa_map-qes_field).
    4    ASSIGN lp_data->* TO <value>.
    5    SELECT SINGLE (wa_map-qes_field) FROM zquadrem_qekko INTO <value> WHERE angnr = _angnr.
    Complains that (wa_map-qes_field) is not defined in line 3.
    Think that the bracket thing is only available via SQL.
    What about CREATE DATA lp_data type ref to object. ?
    Would the above declaration work?
    regards

  • How to read Filter selection variable values into ABAP code

    HI IP Gurus,
    Requierement: In my filter characterstics, i have assigned variables, which use will enter when running th e planning sequence.
    so  variable values entered by user , i would like to get those values into ABAP code and pass them to some function module.
    SO please give me step by step detail how to achive this.
    MY understanding use the below method . but not sure how to proceed.Please let me know abap code to get values.
    GET_TAB_PARAM_DATA_SEL and GET_PARAM_DATA_SEL.
    Please help me.
    Thanks in advance.Will Assign points
    Sania

    Hi Srinivas,
    So In RSPLF1 , in paramters tab, Do i have create structure(str1) and then create component Data selection (Dtsel1) under str1(what setting i have to do here, where should i enter variable value and do i need to give info object name and how do it in code.i tried to following example, not able to get any values in tab_sel .
    It will be great, if you could explain in detail.
    other thing i found out is in Initialization method i can read i_t_data_charsel table values , where it contains filter slected values.but could not pass  these values to execute method
    Is there is any way that i can pass values from init method to execute method.
    A tabular structured parameter with name "MY_TABSTRUC" is defined for the function type. "MY_TABSTRUC" consists of the two parameter components "MY_ELEM" and "MY_DATASEL". You access the parameter values as follows:
    DATA: TAB_PARAM_STRUC TYPE RSPLFA_T_PARAM_STRUC,
           REF_PARAM_STRUC    TYPE REF TO IF_RSPLFA_PARAM_STRUC,
          REF_PARAM_ELEM     TYPE REF TO IF_RSPLFA_PARAM_ELEM,
          REF_PARAM_DATASEL  TYPE REF TO IF_RSPLFA_PARAM_DATESEL,
           L_VAL(20)          TYPE C,
           TAB_SEL            TYPE RSPLF_T_CHARSEL.
    get table of parameter MY_TABSTRUC:
      TAB_PARAM_STRUC = I_R_PARAM_SET->GET_TAB_PARAM_STRUC( 'MY_TABSTRUC' ).
    process all lines:
      LOOP AT TAB_PARAM_STRUC into REF_PARAM_STRUC.
      get component MY_ELEM:
        REF_PARAM_ELEM = REF_PARAM_STRUC->GET_COMP_ELEM( 'MY_ELEM' ).
      get internal value of MY_ELEM:
        REF_PARAM_ELEM->GET_VALUE( IMPORTING E_VALUE = L_VAL ).
      get component MY_DATASEL:
        REF_PARAM_DATASEL = REF_PARAM_STRUC->GET_COMP_DATA_SEL( 'MY_DATASEL' ).
      get data selection table of MY_DATASEL:
        TAB_SEL = REF_PARAM_DATASEL->GET_T_SEL( ).
      ENDLOOP.
    Thanks in Advance..please help me

  • How to read the input field value into ABAP variable?

    Hi All,
    i need a read the value of an input field into an ABAP variable,and i am doing this in the following way
    lstring = request->get_form_field('myFlag').
    here 'myFlag' is the input field name,but this is not returning me any value into lstring.
    I have gone through the SDN and tried to do this.
    could you please help me out to resolve this issue.
    Thanks in Advance,
    Praveena

    Dear Praveena
    In which event are you putting this code. Place it in oninputprocessing event(Page with flow logic Model of coding). Then it will surely work.
    Regards
    Vijay.M

  • Trying to get sysdate- 2yrs and sysdate+2yrs value into variable

    Hi,
    iam Trying to get sysdate- 2yrs and sysdate+2yrs value into variable.But facing the following issue. Please help me out .
    Error :
    p_start_date := select add_months(max(sysdate), -24) from dual;
    ERROR at line 6:
    ORA-06550: line 6, column 25:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null <an identifier>
    <a double-quoted delimited-identifier> <a bind variable>
    continue avg count current exists max min prior sql stddev
    sum variance execute forall merge time timestamp interval
    date <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternat
    ORA-06550: line 7, column 3:
    PLS-00103: Encountered the symbol "P_END_DATE"
    Code
    declare
    p_start_date date;
    p_end_date date;
    begin
    select add_months(max(sysdate),-24) into p_start_date from dual;
    dbms_output.put_line('p_start_date' |p_start_date);
    dbms_output.put_line('p_end_date' | p_end_date);
    end;

    Hi, try:
    SQL> declare
      2 
      3  p_start_date date;
      4  p_end_date date;
      5 
      6  begin
      7 
      8  select add_months(sysdate,-24) into p_start_date from dual;
      9  select add_months(sysdate, 24) into p_end_date from dual;
    10 
    11  dbms_output.put_line('p_start_date: ' ||to_char(p_start_date, 'dd-mm-yyyy hh24:mi:ss'));
    12  dbms_output.put_line('p_end_date: '   ||to_char(p_end_date, 'dd-mm-yyyy hh24:mi:ss'));
    13  end;
    14  /
    p_start_date: 14-04-2007 17:41:34
    p_end_date: 14-04-2011 17:41:34
    PL/SQL procedure successfully completed.

  • Reading BFile datatype value to insert corresponding value into blob

    Hi,
    I have oracle 10.2.0 database.
    I have this table with 3 columns of datatypes
    TableA(id, Blob, BFile)
    now i have pdf files stored in a directory for every id which ranges from 1 till 100.
    for example for id=10, the pdf file name is cr10.pdf
    except that for some id there is no correpsonding pdf's.
    and i have a written a query where for a particular id, i link the corresponding pdf into the BFile. now is there a way where i can view the value of the bfile locator and find whether the bfile is null or not(i mean whether there is a pdf or not existing for that particular id)
    what i need to do is, based on the bfile value i will insert the pdf into the blob column.
    so based on the bfile value(ie whethe rthe pdf exisit or not) i will open the pdf and read the contents into the blob column.
    and somehow i have figure out that a pdf is not exisiting based on the bfile value and then insert a null into the blob column instead of getting an error by trying to read a pdf which doesn't exist.
    Can someone help me, how to find out existance of a file based on bfile value and insert value into blob.
    I want this is script to be automated instead of checking manually a file exists or not.
    Thanks,
    Philip.

    Hi,
    I have oracle 10.2.0 database.
    I have this table with 3 columns of datatypes
    TableA(id, Blob, BFile)
    now i have pdf files stored in a directory for every id which ranges from 1 till 100.
    for example for id=10, the pdf file name is cr10.pdf
    except that for some id there is no correpsonding pdf's.
    and i have a written a query where for a particular id, i link the corresponding pdf into the BFile. now is there a way where i can view the value of the bfile locator and find whether the bfile is null or not(i mean whether there is a pdf or not existing for that particular id)
    what i need to do is, based on the bfile value i will insert the pdf into the blob column.
    so based on the bfile value(ie whethe rthe pdf exisit or not) i will open the pdf and read the contents into the blob column.
    and somehow i have figure out that a pdf is not exisiting based on the bfile value and then insert a null into the blob column instead of getting an error by trying to read a pdf which doesn't exist.
    Can someone help me, how to find out existance of a file based on bfile value and insert value into blob.
    I want this is script to be automated instead of checking manually a file exists or not.
    Thanks,
    Philip.

  • Can you force a value into a read-only numeric data member?

    I have code that will force a value into a numeric data member. Unfortunately the numeric data member in question is read-only. Can you force a value into a read-only numeric data member?

    Andre,
    I think you should get together with the other engineers there at NI. I spoke to one on the phone yesterday and he told me that the read-only aspect relates to writing between the database and PLC. I'm trying to write to the database and he told me that I could do it.

Maybe you are looking for