Results 1 to 4 of 4

Thread: RandomAccessFile? [resolved]

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    RandomAccessFile? [resolved]

    Anyone know how i can open a file for RandomAccess and increment the file pointer from character to character? I open the file in "r" read mode but im not sure if this is the right way to position the file pointer.

    It makes sense since each character should be two bytes even though they are encoded in UTF-8 since they fall within the ASCII range. But all i keep getting is ? marks

    Code:
      import java.io.*; 
      
      public class X{
       public static void main(String[] args){
       try {
       File f = new File("C:\\Java\\Brandon.txt");
       int counter = 0;   
       RandomAccessFile raf = new RandomAccessFile(f, "r");
       
      while(true){
        System.out.println(raf.readChar());
        raf.seek(counter += 2);
      }
          
     }catch(IOException e){}
       }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width