RandomAccessFile Introduction : RandomAccessFile « File « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » File » RandomAccessFile 
11. 40. 1. RandomAccessFile Introduction
  1. A RandomAccessFile employs an internal pointer that points to the next byte to read.
  2. This pointer is zero-based and the first byte is indicated by index 0.
  3. When first created, a RandomAccessFile points to the first byte.
  4. You can change the pointer's position by invoking the seek method.
  5. The skipBytes method moves the pointer by the specified number of bytes.
  6. If skipping offset number of bytes would pass the end of file, the internal pointer will only move to as much as the end of file.
  7. The skipBytes method returns the actual number of bytes skipped.

When opening a file using a RandomAccessFile, you can choose whether to open it read-only or read write.

public RandomAccessFile (File file, String modethrows FileNotFoundException
public RandomAccessFile (String filePath, String modethrows FileNotFoundException

The value of mode can be one of these:

"r".     Open for reading only.

      "rw".    Open for reading and writing. 
               If the file does not already exist, RandomAccessFile creates the file.

      "rws".   Open for reading and writing and require that every update to the file's content and metadata be written synchronously.

      "rwd".   Open for reading and writing and require that every update to the file's content (but not metadatabe written synchronously.
11. 40. RandomAccessFile
11. 40. 1. RandomAccessFile Introduction
11. 40. 2. Employs RandomAccessFile to store ints and changes the value of the third int.
11. 40. 3. Seek in RandomAccessFile
11. 40. 4. Getting FileChannel from RandomAccessFile
11. 40. 5. Write int to RandomAccessFile using FileChannel
11. 40. 6. Use RandomAccessFile to save and read
11. 40. 7. Use RandomAccessFile to reverse a file
11. 40. 8. Test file pointer manipulation between FileChannel and RandomAccessFile objects.
11. 40. 9. Appending data to existing file
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.