• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

urgent ..please look at code

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic