Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-10-2007, 08:15 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,681
Rep Power: 4
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Accessing a file randomly
Sometimes it is required to randomly access a file. Following code is an example where a file is randomly read.

Code:
            File file = new File("file.out");
            RandomAccessFile ran = new RandomAccessFile(file, "rw");

            byte ch = ran.readByte();
            System.out.println("Read first character of file: " + (char)ch);

            // reading remaining line
            // Prontout text from the current cursor position
            System.out.println("Read full line: " + ran.readLine());


            // Seek to the end of file
            ran.seek(file.length());

            // appendind text at the end of file
            ran.write(0x0A);
            ran.writeBytes("This will complete the example");

            ran.close();
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Randomly Accessing Files (3) JavaForums Java Blogs 0 12-13-2007 10:11 AM
Randomly Accessing Files (2) JavaForums Java Blogs 0 12-12-2007 05:50 PM
Randomly Accessing Files (1) JavaForums Java Blogs 0 12-12-2007 01:50 PM
Randomly accessing files Java Tip Java Tips 0 12-12-2007 10:46 AM
Randomly accessing a text file bugger New To Java 1 12-07-2007 06:20 PM


All times are GMT +2. The time now is 03:52 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org