Read line N from a File

Hi!
I don't now how can I read for example line number 5 of a file, this is the way I do , but it doesn't work. What the programme should do is read the first line and then read line number 5, but it read line number 2!!!
Could someone help me or paste a code ?
This is my code:
file = new File("fich");
try{
fileR = new FileReader(file);     
catch(FileNotFoundException e){}
BufferedReader bfr = new BufferedReader(fileR);
LineNumberReader lnr = new LineNumberReader(bfr);
String line=null;
line=lnr.readLine();
System.out.println("Line number:: " + lnr.getLineNumber());
System.out.println(" ----> " + line);
lnr.setLineNumber(5);
System.out.println("Line number:: " + lnr.getLineNumber());
line=lnr.readLine();
System.out.println("Line number:: " + lnr.getLineNumber());
System.out.println(" ----> " + line);
Thanks
Andreia

I was looking through the bug reports (see 4178689) and this is what I found in the answer:
"The line number kept in LineNumberReader is not the same as the physical line
number in the input file. It is just a local counter in the reader. Setting
this number only results in the reader start counting from a new number from
the next readLine(), it does not allow jumping from one line to another in
the physical data file. The readLine() call just read lines one after another
from the underlying stream, unless reset() or skip() is called."
rbelovoskey presented a quick work-around:
public void navigateForwardToLine(LineNumberReader lineNumberReaderIn, int intLineToGoTo)
int intInitialLine = lineNumberReaderIn.getLineNumber();
try{
   for( int intCurrentLine = intInitialLine; intCurrentLine < intLineToGoTo; intCurrentLine++)
        lineNumberReaderIn.readLine();
   }catch(IOException ioe){
     ioe.printStackTrace();

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

  • 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

  • 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.

  • 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 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 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 the same line twice from a file

    I have code which I have to read the same line of a file when I want. Reading the file by line line to an arraylist or a variable is not the thing that I want. I just want to mark a line position in a file and read to start from the position. Random Files uses seek to do this, but I have to convert bytes and parse them into lines.
    Does bufferedreader has some property or another reading method support this?

    mark() and reset() ?
    Read the API docs for a change http://java.sun.com/javase/6/docs/api/java/io/BufferedReader.html

  • 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 in data from a file

    Hi,
    I am tring to read data from a file into my Web Service program. Its a plain text file with item descriptions and price info etc. At the moment I'm trying BufferedReader in = new BufferedReader(...) but I keep getting an exception with Tomcat not being able to locate my file.
    Should there be a specific location for files such as this? Or do I need to add a path to a properties or build file? I have tried many different system locations.
    I've tried to follow the Sun coffee bean example, but I have found it very complex and would appreciate a clear simple answer.
    This is driving me crazy and any help would be much appreciated.
    //Daniel.

    public static void main(String argv[]) {
         try {
              String filename="absolute path to some file";
              BufferedReader in = new BufferedReader(
    (Reader)new FileReader(filename)
              String line;
              while ((line=in.readLine()) != null)
    System.out.println(line);
         catch (Exception e) {
              System.out.println(e.toString());

Maybe you are looking for

  • How to get a notification or an alert in the workbench

    Hi Experts, I am creating 2 schedules,one to be completed on 1stAug and other on 2ndAug,where the 1st one depends on the other. Now my requirement is that , If the approver forgets to approve on 1stAug,he should get a notification or an alert or an e

  • Should be Oracle database bin path in PATH BEFORE Soa Suite bin path ?

    On my local computer I installed Oracle Database 10g Express AND Soa Suite. Hence the PATH environment variable contains (among others) two pathes: one for Soa Suite and one for database 10g.e.g.: Path=D:\soa\v10.1.3.1\OracleAS_1\jdk\bin;D:\soa\v10.1

  • CUDA Acceleration and Scaling

    I am running Premiere Pro CC on a Windows 7 core i5 with 16 gigs of ram. I frequently need to produce both a Blu ray disk as well as a standard DVD. I am getting good results exporting as a mpeg 2 DVD and importing that into Encore as a timeline. Tha

  • Function Security Menu Report under SYSADMIN responsibility

    Friends - Using "Function Security Menu Report" i can able to find out what functions and menus are under particular responsibility. But we have nearly 100 responsibilities where i need to submit this requests more than 100 times. Is there any SQL Sc

  • Bought a used 4S from a business, employee has it locked???

    I bought a used 4s from a home health agency that has since switched the employees to tablets. The employee they have issued this phone to had activated the "Find My Phone" feature on this phone and has since forgotten the password for her Icloud acc