[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Issue with RandomaccessFile ReadLine method.

Posted on 2007-03-26
3
Medium Priority
?
659 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:
Suggested Courses

649 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