Solved

Issue with RandomaccessFile ReadLine method.

Posted on 2007-03-26
3
598 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
  • 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 58
changeXy challenge 13 58
wordcount challenge 11 78
Cipher Configuration on Apache HTTPD 4 24
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now