Results 1 to 5 of 5
  1. #1
    peliukasss is offline Member
    Join Date
    Feb 2010
    Posts
    21
    Rep Power
    0

    Default read from RandomAccessFile

    Hello everyone,

    I have situation which needs to be done well. I'm new to java, so sorry for stupid questions.

    I have text file which contains:
    Java Code:
    text text text text text WORD text text text 
    text text WORD text text  text text text 
    text text text text text  text text text 
    text text text WORD text text text text 
    text text text text text WORD text text text
    How I have to write those lines to RandomAccessFile that later I could be able to use seek method to seek WORD index and get results like this:

    Java Code:
    text text text text text WORD text text text 
                       text text WORD text text  text text text  
                 text text text WORD text text text text 
    text text text text text WORD text text text
    Search word must be in one column and print only those lines which contains that word I'm searching.

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    Skim through the java tips. I know you'll find your answer in there. I found my answer which was similar to this in searching words.

    http://www.java-forums.org/java-tips...-file-end.html

    I also used

    Scanner s = new Scanner(GetProperties).useDelimiter(",");
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    Why do you want to use the RandomAccessFile when you want to read lines?
    By line I mean a sequence of bytes ending with the newline character.

    What is the relationship between the two posts of the file that you show?
    In the second there are some leading spaces added to some of the "lines"
    and the "line" without the String "WORD" is gone.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    If you "quote" the OP you'll see the layout is such that all the WORD's are in line. The formatting hasn't held up (since the font isn't monospaced).

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

Similar Threads

  1. Writing the data into RandomAccessFile
    By vasavi.singh in forum New To Java
    Replies: 5
    Last Post: 01-31-2013, 07:12 AM
  2. RandomAccessFile
    By swati.jyoti in forum New To Java
    Replies: 1
    Last Post: 04-22-2009, 04:05 PM
  3. Replies: 5
    Last Post: 10-17-2008, 02:13 PM
  4. How to read the following
    By rrp in forum New To Java
    Replies: 0
    Last Post: 12-03-2007, 06:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •