Java Doc for RandomAccessFile.java in  » Apache-Harmony-Java-SE » java-package » java » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
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 Source Code / Java Documentation » Apache Harmony Java SE » java package » java.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.io.RandomAccessFile

RandomAccessFile
public class RandomAccessFile implements DataInput,DataOutput,Closeable(Code)
RandomAccessFile is a class which allows positioning of the next read anywhere in the file. This is useful for reading specific locations of files or following links within a file. Most input classes only support forward skipping.



Constructor Summary
public  RandomAccessFile(File file, String mode)
     Constructs a new RandomAccessFile on the File file and opens it according to the access String in mode.
public  RandomAccessFile(String fileName, String mode)
     Constructs a new RandomAccessFile on the file named fileName and opens it according to the access String in mode.

Method Summary
public  voidclose()
     Close this RandomAccessFile.
final public synchronized  FileChannelgetChannel()
     Answers the FileChannel equivalent to this stream.

The file channel is write-only and has an initial position within the file that is the same as the current position of this FileOutputStream within the file.

final public  FileDescriptorgetFD()
     Answers the FileDescriptor representing the operating system resource for this RandomAccessFile.
public  longgetFilePointer()
     Answers the current position within this RandomAccessFile.
public  longlength()
     Answers the current length of this RandomAccessFile in bytes.
public  intread()
     Reads a single byte from this RandomAccessFile and returns the result as an int.
public  intread(byte[] buffer)
     Reads bytes from this RandomAccessFile into the byte array buffer.
public  intread(byte[] buffer, int offset, int count)
     Reads at most count bytes from this RandomAccessFile and stores them in byte array buffer starting at offset.
final public  booleanreadBoolean()
     Reads a boolean from this stream.
final public  bytereadByte()
     Reads an 8-bit byte value from this stream.
final public  charreadChar()
     Reads a 16-bit character value from this stream.
final public  doublereadDouble()
     Reads a 64-bit double value from this stream.
final public  floatreadFloat()
     Reads a 32-bit float value from this stream.
final public  voidreadFully(byte[] buffer)
     Reads bytes from this stream into the byte array buffer.
final public  voidreadFully(byte[] buffer, int offset, int count)
     Read bytes from this stream and stores them in byte array buffer starting at offset offset.
final public  intreadInt()
     Reads a 32-bit integer value from this stream.
final public  StringreadLine()
     Answers a String representing the next line of text available in this BufferedReader.
final public  longreadLong()
     Reads a 64-bit long value from this stream.
final public  shortreadShort()
     Reads a 16-bit short value from this stream.
final public  StringreadUTF()
     Reads a UTF format String from this Stream.
final public  intreadUnsignedByte()
     Reads an unsigned 8-bit byte value from this stream and returns it as an int.
final public  intreadUnsignedShort()
     Reads a 16-bit unsigned short value from this stream and returns it as an int.
public  voidseek(long pos)
     Seeks to the position pos in this RandomAccessFile.
public  voidsetLength(long newLength)
     Set the length of this file to be newLength.
public  intskipBytes(int count)
     Skips count number of bytes in this stream.
public  voidwrite(byte[] buffer)
     Writes the entire contents of the byte array buffer to this RandomAccessFile starting at the current file pointer.
public  voidwrite(byte[] buffer, int offset, int count)
     Writes count bytes from the byte array buffer starting at offset to this RandomAccessFile starting at the current file pointer..
public  voidwrite(int oneByte)
     Writes the specified byte oneByte to this RandomAccessFile starting at the current file pointer.
final public  voidwriteBoolean(boolean val)
     Writes a boolean to this output stream.
final public  voidwriteByte(int val)
     Writes a 8-bit byte to this output stream.
final public  voidwriteBytes(String str)
     Writes the low order 8-bit bytes from a String to this output stream.
final public  voidwriteChar(int val)
     Writes the specified 16-bit character to the OutputStream.
final public  voidwriteChars(String str)
     Writes the specified 16-bit characters contained in str to the OutputStream.
final public  voidwriteDouble(double val)
     Writes a 64-bit double to this output stream.
final public  voidwriteFloat(float val)
     Writes a 32-bit float to this output stream.
final public  voidwriteInt(int val)
     Writes a 32-bit int to this output stream.
final public  voidwriteLong(long val)
     Writes a 64-bit long to this output stream.
final public  voidwriteShort(int val)
     Writes the specified 16-bit short to the OutputStream.
final public  voidwriteUTF(String str)
     Writes the specified String out in UTF format.


Constructor Detail
RandomAccessFile
public RandomAccessFile(File file, String mode) throws FileNotFoundException(Code)
Constructs a new RandomAccessFile on the File file and opens it according to the access String in mode. The access mode may be one of "r" for read access only, or "rw" for read/write access.
Parameters:
  file - the File to open.
Parameters:
  mode - "r" for read only, or "rw" for read/write.
throws:
  FileNotFoundException - If the mode is incorrect or the File cannot beopened in the requested mode.
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)



RandomAccessFile
public RandomAccessFile(String fileName, String mode) throws FileNotFoundException(Code)
Constructs a new RandomAccessFile on the file named fileName and opens it according to the access String in mode. The file may be absolute or relative to the System property "user.dir". The access mode may be one of "r" for read access only, or "rw" for read/write access.
Parameters:
  fileName - the filename of the file to open.
Parameters:
  mode - "r" for read only, or "rw" for read/write.
throws:
  FileNotFoundException - If the mode is incorrect or the file cannot beopened in the requested mode.
See Also:   java.lang.SecurityManager.checkRead(FileDescriptor)
See Also:   java.lang.SecurityManager.checkWrite(FileDescriptor)




Method Detail
close
public void close() throws IOException(Code)
Close this RandomAccessFile.
throws:
  IOException - If an error occurs attempting to close this RandomAccessFile.



getChannel
final public synchronized FileChannel getChannel()(Code)
Answers the FileChannel equivalent to this stream.

The file channel is write-only and has an initial position within the file that is the same as the current position of this FileOutputStream within the file. All changes made to the underlying file descriptor state via the channel are visible by the output stream and vice versa.

the file channel representation for this FileOutputStream.



getFD
final public FileDescriptor getFD() throws IOException(Code)
Answers the FileDescriptor representing the operating system resource for this RandomAccessFile. the FileDescriptor for this RandomAccessFile.
throws:
  IOException - If an error occurs attempting to get the FileDescriptor ofthis RandomAccessFile.



getFilePointer
public long getFilePointer() throws IOException(Code)
Answers the current position within this RandomAccessFile. All reads and writes take place at the current file pointer position. the current file pointer position.
throws:
  IOException - If an error occurs attempting to get the file pointerposition of this RandomAccessFile.



length
public long length() throws IOException(Code)
Answers the current length of this RandomAccessFile in bytes. the current file length in bytes.
throws:
  IOException - If an error occurs attempting to get the file length of thisRandomAccessFile.



read
public int read() throws IOException(Code)
Reads a single byte from this RandomAccessFile and returns the result as an int. The low-order byte is returned or -1 of the end of file was encountered. the byte read or -1 if end of file.
throws:
  IOException - If an error occurs attempting to read from thisRandomAccessFile.
See Also:   RandomAccessFile.write(byte[])
See Also:   RandomAccessFile.write(byte[],int,int)
See Also:   RandomAccessFile.write(int)



read
public int read(byte[] buffer) throws IOException(Code)
Reads bytes from this RandomAccessFile into the byte array buffer. The number of bytes actually read is returned.
Parameters:
  buffer - the buffer to read bytes into the number of bytes actually read or -1 if end of file.
throws:
  IOException - If an error occurs attempting to read from thisRandomAccessFile.
See Also:   RandomAccessFile.write(byte[])
See Also:   RandomAccessFile.write(byte[],int,int)
See Also:   RandomAccessFile.write(int)



read
public int read(byte[] buffer, int offset, int count) throws IOException(Code)
Reads at most count bytes from this RandomAccessFile and stores them in byte array buffer starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of file was encountered.
Parameters:
  buffer - the byte array in which to store the read bytes.
Parameters:
  offset - the offset in buffer to store the read bytes.
Parameters:
  count - the maximum number of bytes to store in buffer. the number of bytes actually read or -1 if end of file.
throws:
  IOException - If an error occurs attempting to read from thisRandomAccessFile.
See Also:   RandomAccessFile.write(byte[])
See Also:   RandomAccessFile.write(byte[],int,int)
See Also:   RandomAccessFile.write(int)



readBoolean
final public boolean readBoolean() throws IOException(Code)
Reads a boolean from this stream. boolean the next boolean value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeBoolean(boolean)



readByte
final public byte readByte() throws IOException(Code)
Reads an 8-bit byte value from this stream. byte the next byte value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeByte(int)



readChar
final public char readChar() throws IOException(Code)
Reads a 16-bit character value from this stream. char the next char value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeChar(int)



readDouble
final public double readDouble() throws IOException(Code)
Reads a 64-bit double value from this stream. double the next double value from the sourcestream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeDouble(double)



readFloat
final public float readFloat() throws IOException(Code)
Reads a 32-bit float value from this stream. float the next float value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeFloat(float)



readFully
final public void readFully(byte[] buffer) throws IOException(Code)
Reads bytes from this stream into the byte array buffer. This method will block until buffer.length number of bytes have been read.
Parameters:
  buffer - the buffer to read bytes into
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.write(byte[])
See Also:   DataOutput.write(byte[]intint)



readFully
final public void readFully(byte[] buffer, int offset, int count) throws IOException(Code)
Read bytes from this stream and stores them in byte array buffer starting at offset offset. This method blocks until count number of bytes have been read.
Parameters:
  buffer - the byte array in which to store the read bytes.
Parameters:
  offset - the offset in buffer to store the read bytes.
Parameters:
  count - the maximum number of bytes to store in buffer.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.write(byte[])
See Also:   DataOutput.write(byte[]intint)



readInt
final public int readInt() throws IOException(Code)
Reads a 32-bit integer value from this stream. int the next int value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeInt(int)



readLine
final public String readLine() throws IOException(Code)
Answers a String representing the next line of text available in this BufferedReader. A line is represented by 0 or more characters followed by '\n', '\r', "\n\r" or end of stream. The String does not include the newline sequence. String the contents of the line or null if no characters wereread before end of stream.
throws:
  IOException - If the BufferedReader is already closed or some other IOerror occurs.



readLong
final public long readLong() throws IOException(Code)
Reads a 64-bit long value from this stream. long the next long value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeLong(long)



readShort
final public short readShort() throws IOException(Code)
Reads a 16-bit short value from this stream. short the next short value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeShort(int)



readUTF
final public String readUTF() throws IOException(Code)
Reads a UTF format String from this Stream. String the next UTF String from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeUTF(java.lang.String)



readUnsignedByte
final public int readUnsignedByte() throws IOException(Code)
Reads an unsigned 8-bit byte value from this stream and returns it as an int. int the next unsigned byte value from the source stream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeByte(int)



readUnsignedShort
final public int readUnsignedShort() throws IOException(Code)
Reads a 16-bit unsigned short value from this stream and returns it as an int. int the next unsigned short value from the sourcestream.
throws:
  IOException - If a problem occurs reading from this DataInputStream.
See Also:   DataOutput.writeShort(int)



seek
public void seek(long pos) throws IOException(Code)
Seeks to the position pos in this RandomAccessFile. All read/write/skip methods sent will be relative to pos.
Parameters:
  pos - the desired file pointer position
throws:
  IOException - If the stream is already closed or another IOExceptionoccurs.



setLength
public void setLength(long newLength) throws IOException(Code)
Set the length of this file to be newLength. If the current file is smaller, it will be expanded and the filePosition will be set to the new file length. If the newLength is smaller then the file will be truncated.
Parameters:
  newLength - the desired file length
throws:
  IOException - If the stream is already closed or another IOExceptionoccurs.



skipBytes
public int skipBytes(int count) throws IOException(Code)
Skips count number of bytes in this stream. Subsequent read()'s will not return these bytes unless reset() is used.
Parameters:
  count - the number of bytes to skip. the number of bytes actually skipped.
throws:
  IOException - If the stream is already closed or another IOExceptionoccurs.



write
public void write(byte[] buffer) throws IOException(Code)
Writes the entire contents of the byte array buffer to this RandomAccessFile starting at the current file pointer.
Parameters:
  buffer - the buffer to be written.
throws:
  IOException - If an error occurs trying to write to this RandomAccessFile.
See Also:   RandomAccessFile.read()
See Also:   RandomAccessFile.read(byte[])
See Also:   RandomAccessFile.read(byte[],int,int)



write
public void write(byte[] buffer, int offset, int count) throws IOException(Code)
Writes count bytes from the byte array buffer starting at offset to this RandomAccessFile starting at the current file pointer..
Parameters:
  buffer - the bytes to be written
Parameters:
  offset - offset in buffer to get bytes
Parameters:
  count - number of bytes in buffer to write
throws:
  IOException - If an error occurs attempting to write to thisRandomAccessFile.
throws:
  IndexOutOfBoundsException - If offset or count are outside of bounds.
See Also:   RandomAccessFile.read()
See Also:   RandomAccessFile.read(byte[])
See Also:   RandomAccessFile.read(byte[],int,int)



write
public void write(int oneByte) throws IOException(Code)
Writes the specified byte oneByte to this RandomAccessFile starting at the current file pointer. Only the low order byte of oneByte is written.
Parameters:
  oneByte - the byte to be written
throws:
  IOException - If an error occurs attempting to write to thisRandomAccessFile.
See Also:   RandomAccessFile.read()
See Also:   RandomAccessFile.read(byte[])
See Also:   RandomAccessFile.read(byte[],int,int)



writeBoolean
final public void writeBoolean(boolean val) throws IOException(Code)
Writes a boolean to this output stream.
Parameters:
  val - the boolean value to write to the OutputStream
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readBoolean



writeByte
final public void writeByte(int val) throws IOException(Code)
Writes a 8-bit byte to this output stream.
Parameters:
  val - the byte value to write to the OutputStream
throws:
  java.io.IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   RandomAccessFile.readByte()
See Also:   RandomAccessFile.readUnsignedByte()



writeBytes
final public void writeBytes(String str) throws IOException(Code)
Writes the low order 8-bit bytes from a String to this output stream.
Parameters:
  str - the String containing the bytes to write to the OutputStream
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   RandomAccessFile.read(byte[])
See Also:   RandomAccessFile.read(byte[],int,int)
See Also:   RandomAccessFile.readFully(byte[])
See Also:   RandomAccessFile.readFully(byte[],int,int)



writeChar
final public void writeChar(int val) throws IOException(Code)
Writes the specified 16-bit character to the OutputStream. Only the lower 2 bytes are written with the higher of the 2 bytes written first. This represents the Unicode value of val.
Parameters:
  val - the character to be written
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readChar



writeChars
final public void writeChars(String str) throws IOException(Code)
Writes the specified 16-bit characters contained in str to the OutputStream. Only the lower 2 bytes of each character are written with the higher of the 2 bytes written first. This represents the Unicode value of each character in str.
Parameters:
  str - the String whose characters are to be written.
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readChar



writeDouble
final public void writeDouble(double val) throws IOException(Code)
Writes a 64-bit double to this output stream. The resulting output is the 8 bytes resulting from calling Double.doubleToLongBits().
Parameters:
  val - the double to be written.
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readDouble



writeFloat
final public void writeFloat(float val) throws IOException(Code)
Writes a 32-bit float to this output stream. The resulting output is the 4 bytes resulting from calling Float.floatToIntBits().
Parameters:
  val - the float to be written.
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readFloat



writeInt
final public void writeInt(int val) throws IOException(Code)
Writes a 32-bit int to this output stream. The resulting output is the 4 bytes, highest order first, of val.
Parameters:
  val - the int to be written.
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readInt



writeLong
final public void writeLong(long val) throws IOException(Code)
Writes a 64-bit long to this output stream. The resulting output is the 8 bytes, highest order first, of val.
Parameters:
  val - the long to be written.
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readLong



writeShort
final public void writeShort(int val) throws IOException(Code)
Writes the specified 16-bit short to the OutputStream. Only the lower 2 bytes are written with the higher of the 2 bytes written first.
Parameters:
  val - the short to be written
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readShort
See Also:   DataInput.readUnsignedShort



writeUTF
final public void writeUTF(String str) throws IOException(Code)
Writes the specified String out in UTF format.
Parameters:
  str - the String to be written in UTF format.
throws:
  IOException - If an error occurs attempting to write to thisDataOutputStream.
See Also:   DataInput.readUTF



Methods inherited from java.lang.Object
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object object)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final public Class<? extends Object> getClass()(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
final public void notify()(Code)(Java Doc)
final public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final public void wait(long millis, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait(long millis) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.