Read method calls from a file.

I am working on an event driven program that has various events listed in a file that are supposed to be read in and used. I can go through the pain staking process of using StringTokenizer and .substring to figure which event is which, but I want to know if there would be an easier process of reading in the events. (Can't Cast them)
Any suggestions?
Shawn

Hi Again
U can go for StreamTokenizer in java.io
this is useful for tokenizing a Stream based on delimiters
It has Two Cons for both Type of Streams either Char or Bin
public java.io.StreamTokenizer(java.io.InputStream);
public java.io.StreamTokenizer(java.io.Reader);
The StreamTokenizer class takes an input stream and parses it into "tokens", allowing the tokens to be read one at a time. The parsing process is controlled by a table and a number of flags that can be set to various states. The stream tokenizer can recognize identifiers, numbers, quoted strings, and various comment styles.
U hav to invoke a method called nextToken Form which u will get a token which can be compared to find wether it is a word or character ....using the constanrs avlbl in StreamTokenizer class
TT_WORD indicates that the token is a word.
TT_NUMBER indicates that the token is a number.
TT_EOL indicates that the end of line has been read. The field can only have this value if the eolIsSignificant method has been called with the argument true.
TT_EOF indicates that the end of the input stream has been reached
Alll the Very Best
Rgds
Sriram

Similar Messages

  • Reading long text from excel file to an internal table

    Hi
    Can any body tell me how to read long text from excel file to an internal table.
    When i am using this FM KCD_EXCEL_OLE_TO_INT_CONVERT then it is reading only 32 characters from each cell.
    But in my excel sheet in one of the cell has very long text which i need to upload into a internal table.
    may i know which FM or what logic i need to use for this problem.
    Regards

    Hi,
    Here is an example program.  It will upload an Excel file with two columns.  You could also assign the Excel structure dynamically, but I wanted to keep the example simple.  The main point is that the internal table (it_excel in this example) must match the Excel structure that you want to convert.
    Remember, this is just an example to help you figure out how to properly use the technique.  It will certainly need to be modified to fit your requirements, and as always there may be a better way to get the Excel converted... this is just one possibility that has worked for me in the past.
    *& Report  zexcel_upload_test                            *
    REPORT  zexcel_upload_test.
    TYPE-POOLS: truxs.
    TYPES: BEGIN OF ty_excel,
             col_a(10) TYPE n,
             col_b(35) TYPE c,
           END OF ty_excel.
    DATA: l_data_tab         TYPE TABLE OF string,
          l_text_data        TYPE truxs_t_text_data,
          l_gui_filename     TYPE string,
          it_excel           TYPE TABLE OF ty_excel.
    FIELD-SYMBOLS: <wa_excel>  TYPE ty_excel.
    PARAMETERS: p_file TYPE rlgrap-filename.
    * Pass the file name in the correct format
    l_gui_filename = p_file.
    * Upload data from PC
    CALL METHOD cl_gui_frontend_services=>gui_upload
      EXPORTING
        filename                = l_gui_filename
        filetype                = 'ASC'
        has_field_separator     = 'X'
      CHANGING
        data_tab                = l_data_tab
      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 ...
      EXIT.
    ENDIF.
    * Convert from Excel into the appropriate itab
    l_text_data[] = l_data_tab[].
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_field_seperator    = 'X'
        i_tab_raw_data       = l_text_data
        i_filename           = p_file
      TABLES
        i_tab_converted_data = it_excel
      EXCEPTIONS
        conversion_failed    = 1
        OTHERS               = 2.
    IF sy-subrc <> 0.
    *   MESSAGE ...
      EXIT.
    ENDIF.
    LOOP AT it_excel ASSIGNING <wa_excel>.
    *  Do something here...
    ENDLOOP.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      PERFORM filename_get CHANGING p_file.
    *       FORM filename_get                                             *
    FORM filename_get CHANGING p_in_file TYPE rlgrap-filename.
      DATA: l_in_file  TYPE string,
            l_filetab  TYPE filetable,
            wa_filetab TYPE LINE OF filetable,
            l_rc       TYPE i,
            l_action   TYPE i,
            l_init_dir TYPE string.
    * Set the initial directory to whatever you want it to be
      l_init_dir = 'C:\'.
    * Call the file open dialog without multiselect
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title            = 'Load file'
          default_extension       = '.XLS'
          default_filename        = l_in_file
          initial_directory       = l_init_dir
          multiselection          = 'X'
        CHANGING
          file_table              = l_filetab
          rc                      = l_rc
          user_action             = l_action
        EXCEPTIONS
          file_open_dialog_failed = 1
          cntl_error              = 2
          error_no_gui            = 3
          OTHERS                  = 4.
      IF sy-subrc <> 0.
        REFRESH l_filetab.
      ENDIF.
    * Read the selected filename
      READ TABLE l_filetab INTO wa_filetab INDEX 1.
      IF sy-subrc = 0.
        p_in_file = wa_filetab-filename.
      ENDIF.
    ENDFORM.                    " filename_get
    Regards,
    Jamie

  • Code for reading particular  fields from the file placed in application

    hi,
    code for reading particular  fields from the file placed in application server in to the internal table.

    Hi,
    Use the GUI_UPLOAD FM to upload the File into ur Internal Table.
    DATA : FILE_TABLE TYPE FILE_TABLE OCCURS 0,
             fwa TYPE FILE_TABLE,
             FILENAME TYPE STRING,
             RC TYPE I.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      EXPORTING
        WINDOW_TITLE            = 'Open File'
       DEFAULT_EXTENSION       =
       DEFAULT_FILENAME        =
       FILE_FILTER             =
       INITIAL_DIRECTORY       =
       MULTISELECTION          =
       WITH_ENCODING           =
      CHANGING
        FILE_TABLE              = FILE_TABLE
        RC                      = RC
       USER_ACTION             =
       FILE_ENCODING           =
      EXCEPTIONS
        FILE_OPEN_DIALOG_FAILED = 1
        CNTL_ERROR              = 2
        ERROR_NO_GUI            = 3
        NOT_SUPPORTED_BY_GUI    = 4
        others                  = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ TABLE FILE_TABLE INDEX 1 into fwa.
    FILENAME = fwa-FILENAME.
        CALL FUNCTION 'GUI_UPLOAD'
             EXPORTING
                  filename                = filename
                  FILETYPE                = 'DAT'
           IMPORTING
                FILELENGTH              =
             TABLES
                  data_tab                = itab
             EXCEPTIONS
                  file_open_error         = 1
                  file_read_error         = 2
                  no_batch                = 3
                  gui_refuse_filetransfer = 4
                  invalid_type            = 5
                  OTHERS                  = 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.
    Regards,
    Balakumar.G
    Reward Points if helpful.

  • How to read a byte[] from a file

    Hi can someone help me to read a byte[] from a file. I need to save a byte[] to a file and then retrieve it later can someone help in this..
    Thanx

    there are actually docs on the classes ByteArrayInputStream and ByteArrayOutputStream here:
    http://java.sun.com/javase/6/docs/api/
    go there (copy & paste in browser) and text search for the above classes.
    Then read into it. That way, you will come to a better comprehension of the entire thing. You may as well want to read this:
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    And for the future: if you have general problems, search API docs and tutorials first and solve them yourself. The guys around here can get pretty annoyed about "Teach me the entire Java Thing" (also called "someone do my homework") requests.
    If you have a special problem, ie an Exception you don?t understand or a method wich you don?t know how it works, everybody will like to help you.
    Only few real serial killers frequent these forums.

  • How can I input read a line from a file and output it into the screen?

    How can I input read a line from a file and output it into the screen?
    If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
    Any help will be appreciate!
    ======START FILE default.html ========
    <html>
    <body>
    <br><br>
    <center>
    <font size=4 face=arial color=#336699>
    <b>Welcome to a DerekTran's Website!</b><br>
    Underconstructions.... <br>
    </font> </center>
    <font size=3 face=arial color=black> <br>
    Hello,<br>
    <br>
    I've been using the PWS to run the website on NT workstation 4.0. It was working
    fine. <br>
    The URL should be as below: <br>
    http://127.0.0.1/index.htm or http://localhost/index.htm
    <p>And suddently, it stops working, it can't find the connection. I tried to figure
    out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
    know what's going on? Please see the link for more.... I believe that I setup
    everything correctly and the bugs still flying in the server.... <br>
    Thank you for your help.</P>
    </font>
    <p><font size=3 face=arial color=black>PeerWebServer.doc
    <br>
    <p><font size=3 face=arial color=black>CannotFindServer.doc
    <br>
    <p><font size=3 face=arial color=black>HOSTS file is not found
    <br>
    <p><font size=3 face=arial color=black>LMHOSTS file
    <br>
    <p><font size=3 face=arial color=black>How to Setup PWS on NT
    <BR>
    <p><font size=3 face=arial color=black>Issdmin doc</BR>
    Please be patient while the document is download....</font>
    <font size=3 face=arial color=black><br>If you have any ideas please drop me a
    few words at [email protected] </font><br>
    <br>
    <br>
    </p>
    <p><!--#include file="Hits.asp"--> </p>
    </body>
    </html>
    ========= END OF FILE ===============

    Hi!
    This is a possible solution to your problem.
    import java.io.*;
    class AddressExtractor {
         public static void main(String args[]) throws IOException{
              //retrieve the commandline parameters
              String fileName = "default.html";
              if (args.length != 0)      fileName =args[0];
               else {
                   System.out.println("Usage : java AddressExtractor <htmlfile>");
                   System.exit(0);
              BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
              StreamTokenizer st = new StreamTokenizer(in);
              st.lowerCaseMode(true);
              st.wordChars('/','/'); //include '/' chars as part of token
              st.wordChars(':',':'); //include ':' chars as part of token
              st.quoteChar('\"'); //set the " quote char
              int i;
              while (st.ttype != StreamTokenizer.TT_EOF) {
                   i = st.nextToken();
                   if (st.ttype == StreamTokenizer.TT_WORD) {          
                        if (st.sval.equals("href")) {               
                             i = st.nextToken(); //the next token (assumed) is the  '=' sign
                             i = st.nextToken(); //then after it is the href value.               
                             getURL(st.sval); //retrieve address
              in.close();
         static void getURL(String s) {     
              //Check string if it has http:// and truncate if it does
              if (s.indexOf("http://") >  -1) {
                   s = s.substring(s.indexOf("http://") + 7, s.length());
              //check if not mailto: do not print otherwise
              if (s.indexOf("mailto:") != -1) return;
              //printout anything after http:// and the next '/'
              //if no '/' then print all
                   if (s.indexOf('/') > -1) {
                        System.out.println(s.substring(0, s.indexOf('/')));
                   } else System.out.println(s);
    }Hope this helps. I used static methods instead of encapsulating everyting into a class.

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • Regarding reading the data from the files without using Stremas

    hai to all of u...
    here i have a problem where i have to read the data from the files without using any streams.
    please guide me how to do this one,if possible by giving with an example
    Thanks & Regard
    M.Ramakrishna

    Simply put, you can't.
    By why do you need to?

  • Reading the data from excel file which is in application server.

    Hi,
    Iam trying to read the data from excel file which is in application server.
    I tried using the function module ALSM_EXCEL_TO_INTERNAL_TABLE. But it didn't work.
    I tried just reading using open data set and read data set it is giving junk characters.
    Please suggest me if you have any solution.
    Best Regards,
    Brahma Reddy

    Hi Narendra,
    Please see the below code I have written
    OPEN DATASET pa_sfile for INPUT in text mode ENCODING  DEFAULT MESSAGE wf_mess.
    CHECK sy-subrc = 0.
    DO.
    READ DATASET pa_sfile INTO wf_string.
    IF sy-subrc <> 0.
    EXIT.
    else.
    split wf_string at wl_# into wf_field1 wf_field2 wa_upload-field3
    wa_upload-field4 wa_upload-field5 wa_upload-field6 wa_upload-field7 wa_upload-field8
    wa_upload-field9 wa_upload-field10 wa_upload-field11 wa_upload-field12 wa_upload-field13
    wa_upload-field14 wa_upload-field15 wa_upload-field16 wa_upload-field17 wa_upload-field18
    wa_upload-field19 wa_upload-field20 wa_upload-field21 wa_upload-field22 wa_upload-field23
    wa_upload-field24 wa_upload-field25 wa_upload-field26 wa_upload-field27 wa_upload-field28
    wa_upload-field29 wa_upload-field30 wa_upload-field31 wa_upload-field32 wa_upload-field33
    wa_upload-field34 wa_upload-field35 wa_upload-field36 .
    wa_upload-field1 = wf_field1.
    wa_upload-field2 = wf_field2.
    append wa_upload to int_upload.
    clear wa_upload.
    ENDIF.
    ENDDO.
    CLOSE DATASET pa_sfile.
    Please note Iam using ECC5.0 and it is not allowing me to declare wl_# as x as in your code.
    Also if Iam using text mode I should use extension encoding etc.( Where as not in your case).
    Please suggest me any other way.
    Thanks for your help,
    Brahma Reddy

  • How to read the data from a file in another computer with user name and password login

    How to read read the data from a file in anohter computer which need to login with user name and password?

    duplicate post:  http://forums.ni.com/t5/LabVIEW/log-on-the-other-computer-with-user-name-and-password/m-p/2061478
    duplicate post:  http://forums.ni.com/t5/LabVIEW/do-need-to-enter-the-user-name-and-password-when-TCP-ip/m-p/2061612
    duplicate post   http://forums.ni.com/t5/LabVIEW/log-on-the-other-computer-with-user-name-and-password/m-p/2060682

  • How to read and write from XL file

    HI ,
    I wanted to read a data from XL file and write a data in XL file by generating a report .Can any body help me out.Many examples are available on discussion forums but when I try to save and run those Vi .I am not able to run Showing error .Please tell what is going wrong as I m having latest labview 8.6 .
    Regards
    Sharmila.karale

    Hi Adnan,
    Here are the examples of Vi which I have downloaded from the forum for my reference
    Regards
    Sharmila.Krale
    Attachments:
    SAVE TO EXCEL.llb ‏128 KB
    excel.llb ‏1618 KB

  • Reading Sheet name from csv file.

    Dear All,
    I am doing one program where i am reading contents from .csv file from oracle forms. I m using utl_file for reading the contents from .csv file.
    But problem is i am having 5 sheets under .csv file and i want to read fifth sheet's data. how do i jump to particular sheet in csv file. please help me in this case. this is very urgent.
    regards,
    Manish n

    I'm not sure of the format of a CSV with sheets : I assume it's a spreadsheet with multiple sheets ?
    I know that using Apache POI you can read (and write) native XLS or XLSX spreadsheets and then iterate through the sheets / rows cells. This requires java knowledge but works really well.
    Steve

  • Kinect Explorer WPF C# read depth data from the file and conversion to skeleton

    Hello,
    I am using Kinect sensor to do some research on biometrics. Since it is impossible to find people to collect some samples, I would like to use samples from the TUM - GAID database, where there exist Color View and Depth View (in .raw format) samples. Therefore,
    I need to read these samples from the file and do a batch processing, instead of performing real-time collecting of samples (where I can take automatically the Skeleton view using the Kinect SDK). So, I need help on
    1. Reading the data from the file (instead of activating the Kinect sensor) and give this data as an input for conversion to a skeleton
    2. Read the .raw files 
    Thank you very much
    Kind regards

    Hiya,
     I doubt this forum, C Sharp, will provide much help. You are asking about the Kinects system not C#
    language. However, you can try this link; http://kinectforwindows.codeplex.com/
    Hope this help. Thanks :)

  • How to read an image from an file using jsp

    reading an image from an file present on local disk using jsp

    Server-local or client-local? First, File I/O, second: better get a new job.

  • READING AND WRITING FROM A FILE(WRITTEN IN ANOTHER LANGUAGE)

    # Comment
    INTEGER Declares integer type variable
    STRING Declares string type variable
    LET Assigns a variable
    CALCULATE Performs an arithmetic calculation
    PRINT Writes data to the console
    PRINTLN As print, but followed by a new line
    END Terminates the program
    Each line of the program must begin with one of these words, and the language should not be case sensitive.
    Tim Brailsford, 2007
    G64ICP
    COMMENT
    Any line beginning with the # character is completely ignored.
    Example:
    # ignore this line!
    INTEGER
    The INTEGER reserved word declares an Integer variable, and assigns a default value of 0 to it.
    Example:
    INTEGER myInt
    This example is equivalent to the Java statment "int myInt=0;"
    STRING
    The STRING reserved word declares a String variable, and assigns an empty string to it.
    Example:
    STRING myString
    This is equivalent to the Java statement "String myString;"
    LET
    This assigns values to variables (either integers, or strings enclosed
    in double quotes).
    Examples:
    LET myInt=42
    LET myString="Hello World!"
    CALCULATE
    This performs numeric calculations upon values or variables, and assigns the result to a variable (which must have
    been declared earlier). Four operators are supported: + *
    and / (for addition, subtraction multiplication and
    integer division respectively).
    Examples:
    CALCULATE myInt=2*2
    CALCULATE myInt=myInt+24
    CALCULATE myInt=intA/intB
    PRINT and PRINTLN
    These words both print to the console the
    only difference being that PRINTLN appends a new line (as does
    System.out.println in Java). These can print either text provided as an argument, or variables (string or integer).
    Examples:
    PRINTLN "Hello World!"
    PRINT myString
    PRINTLN myInt
    END
    This terminates the program, and prints a message to that effect.
    TPL Example
    To the left is an example TPL input file , to
    calculate the factorial of 5. This should produce
    an output similar to that shown overleaf (except
    that calculates the factorial of 10).
    # A TPL Program to calculate the factorial of 5
    INTEGER myInt
    INTEGER factorial
    STRING myString
    LET mystring="Factorial Program"
    LET myInt=5
    CALCULATE factorial=myInt*4
    CALCULATE factorial=factorial*3
    CALCULATE factorial=factorial*2
    Tim Brailsford, 2007
    G64ICP
    PRINTLN mystring
    PRINTLN
    PRINT "The factorial of "
    PRINT myInt
    PRINT " is "
    PRINTLN factorial
    END
    Documentation
    Document your code by writing instructions explaining how to run it, listing all of the files you have submitted,
    and specifying any limitations (eg you might want to say what platforms you would expect it to run on, and what
    platforms you have tested it on). This document should be written as a plain text file (ie ASCII � MS Word binary
    files are not acceptable) � and this file should be called README.TXT. This file should constitute the user
    manual of your program, and should explain exactly how to use your program.
    The README file should be the user manual for your language as implemented.
    NB:
    I want it to read values from the file as given above and execute the answer in the command prompt( as intented in the file above)
    Thanks
    Alam Ikenna

    Hai I have one doubt in doing other peoples homework for them. Why bother?

  • Reading and printing from a file

    I have a method that reads temperatures from a data file and prints them to the monitor. I use a while loop to read each line of the file, but for some reason it doesnt skip the loop when readLine returns null. My question is how do i get the method to stop reading before it returns null...
       public static void printFile(String textFile) throws IOException
            String inputString="";
            BufferedReader inputDataFile=
            new BufferedReader(new FileReader(CENTIGRADE_DATA_FILE));
            while(inputString!=null)
                inputString= inputDataFile.readLine();
                System.out.println(inputString);
            inputDataFile.close();
       

    ok cool thanks for pointing that out guys i appreciate it...now i need to take those temps and convert them from Strings to doubles so they can be converted i tried this but im getting a NumberFormatException error...
    public static void buildReport() throws IOException
            double centigradeTemp=0.00;
            String inputTemp="";
            //Open centigrade temps to be read and converted
            BufferedReader inputDataFile=
            new BufferedReader(new FileReader(CENTIGRADE_DATA_FILE));
            //Open file writer to write report
            PrintWriter outFile=new PrintWriter(new FileWriter("TempReport.txt"));
            //While loop to read a temp, convert it, and write it in the report
            while((inputTemp= inputDataFile.readLine())!=null)
                centigradeTemp=Integer.parseInt(inputTemp);           
                outFile.println(fahrenheit(centigradeTemp));
            outFile.close();
        public static double fahrenheit(double centigrade)
            double fahrenTemp=0.00;
            fahrenTemp=(9/5)*centigrade + 32;
            return fahrenTemp;
     

Maybe you are looking for

  • ICloud versus "on my Mac"

    I'm learning more about iCloud.  Now with my Mac Calendar.  I'm going to start using my Calendars in the iCloud so to access of course on all my devices.  Here is my question:  What happens to my Calendars in iCloud, let's say, if the iCloud failed f

  • Solaris 10 gen the panic message and let the server auto reboot

    My Solaris 10 server would auto reboot at anytime. I think is ip:tcp_unfuse problem. But I don't know how to fix it. Anyone know how to fix this problem!!!!!!! Many Thanks! The following is error information # mdb 0 ::statusdebugging crash dump vmcor

  • Anyone notice a factory protective overlay on their 3G screen

    Hi I was using my iPhone 3G today and noticed something I have not noticed before. Has anyone noticed that there seems to be some short of protective shield on the touch screen? I noticed this because when i looked at the speaker area and the home bu

  • Solaris Installed but wont boot

    Compaq Deskpro 266 This is a straigt forward machine, no whacky install or hardware. 3 Gig HD Whole harddrive has been allocted for sun. The installation goes like a charm, I reboot the machine and pull the cd. It autoboots to the correct partition (

  • Who can help me write a sql?

    Table T has a field F, I want to replace all oldstr with newstr in field F. for example: "abc oldstr end" will be updated to "abc newstr end". Thanks a lot