Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent ..please look at code

 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ernest,
this is going into an infinite loop ,in.txt contains abcde ,please help,anybody.
pradeep

import java.io.*;
public class MARK {
public static void main(String[] args) throws IOException {
RandomAccessFile in = new RandomAccessFile("in.txt","r");
int c,i=0,flag_T=0,j=0;
char cc;
long pos=0;
while ((c = in.read()) != -1){
System.out.println("ch4="+(char)c);
char ch=(char)c;
while ((c >= 'a' && c <= 'z' )|| (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')){
c=in.read();
System.out.println("ch="+(char)c);
}
pos=in.getFilePointer();
in.seek(pos-1);//here i am trying to go one character back to get to
// the EOF character
System.out.println("2");
}//while
}//main
}//MARK
 
Rajesh Kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couple of thoughts...
No. 1:
In the code segment:

You may want to use 'ch' instead of 'c'
No. 2:
If you just get rid of:

your code will exit properly since by having this code, you are just
toggling the while loop between character- 'e' and EOF.
hope this helps.
- Rajesh
 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rajeesh,
I am using the
in.seek(pos-1);

to position the file pointer back at the EOF character ,so that the outer while can exit properly,hope u got it? can you work on it now
thanks
pradeep
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic