Solved

Issue with RandomaccessFile ReadLine method.

Posted on 2007-03-26
3
629 Views
Last Modified: 2012-05-05
Hi,
I implemented the following while loop  after doing a write to a file :
raf_name=new RandomAccessFile("c:\\movie_name29.txt","rw");
raf_name.writeBytes(ss_name + "\r\n");
 while((text1 = raf_name.readLine()) != null)
                        {
                                if (text1.equalsIgnoreCase(searchString_name))
                             {
                                 count_names=count_names+1;
                                 if (count_names >5)
                                    {
                                       
                                       break;
                                       
                                    }
                                 }
                             }


However the code doesn't seems to be getting into the While loop at all. Any reasons why It might be doing so.
Regards
0
Comment
Question by:bjuneja_2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
elfe69 earned 500 total points
ID: 18798106
It is because you are at the end of the file after the call to writeBytes().

add the following between writeBytes() and the while loop and you will return to the beginning of your file:

raf_name.seek(0);
0
 

Author Comment

by:bjuneja_2000
ID: 18798232
Thanx a zillion for pointing that out.. Thats the difference between a novice and expert :- ) ...
0
 
LVL 11

Expert Comment

by:elfe69
ID: 18798235
You're welcome :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
configure dependency in POM for new database 3 43
ejb on wildfly 5 45
hashmap order 17 40
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question