Create random file access
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 1 month ago. Active 11 years, 1 month ago. Viewed 20k times. Any higher performance solutions? Thanks for all the answers. NextBytes data ; File. NextBytes data ; stream. Write data, 0, data. Create, FileAccess. Write, FileShare. Improve this question. Jason Jason 11k 24 24 gold badges 72 72 silver badges bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. The mode argument specifies the access mode in which the file is to be opened. The permitted values and their meanings are: Value. If there is a security manager, its checkRead method is called with the pathname of the file argument as its argument to see if read access to the file is allowed.
If the mode allows writing, the security manager's checkWrite method is also called with the path argument to see if write access to the file is allowed. Parameters: file - the file object mode - the access mode, as described above Throws: IllegalArgumentException - if the mode argument is not equal to one of "r" , "rw" , "rws" , or "rwd" FileNotFoundException - if the mode is "r" but the given file object does not denote an existing regular file, or if the mode begins with "rw" but the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file SecurityException - if a security manager exists and its checkRead method denies read access to the file or the mode is "rw" and the security manager's checkWrite method denies write access to the file See Also: SecurityManager.
String , FileChannel. The position of the returned channel will always be equal to this object's file-pointer offset as returned by the getFilePointer method. Changing this object's file-pointer offset, whether explicitly or by reading or writing bytes, will change the position of the channel, and vice versa.
Changing the file's length via this object will change the length seen via the file channel, and vice versa. Returns: the file channel associated with this file Since: 1. The byte is returned as an integer in the range 0 to 0xx0ff. This method blocks if no input is yet available. Returns: the next byte of data, or -1 if the end of the file has been reached. Not thrown if end-of-file has been reached.
This method blocks until at least one byte of input is available. Parameters: b - the buffer into which the data is read. Returns: the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached. NullPointerException - If b is null. Returns: the total number of bytes read into the buffer, or -1 if there is no more data because the end of this file has been reached. This method reads repeatedly from the file until the requested number of bytes are read.
This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown. Specified by: readFully in interface DataInput Parameters: b - the buffer into which the data is read.
Throws: EOFException - if this file reaches the end before reading all the bytes. This method may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. This method never throws an EOFException. The actual number of bytes skipped is returned.
If n is negative, no bytes are skipped. Specified by: skipBytes in interface DataInput Parameters: n - the number of bytes to be skipped. Returns: the actual number of bytes skipped. The write starts at the current file pointer. Specified by: write in interface DataOutput Parameters: b - the byte to be written. Specified by: write in interface DataOutput Parameters: b - the data. Returns: the offset from the beginning of the file, in bytes, at which the next read or write occurs.
The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file. Parameters: pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Returns: the length of this file, measured in bytes. If the present length of the file as returned by the length method is greater than the newLength argument then the file will be truncated. In this case, if the file offset as returned by the getFilePointer method is greater than newLength then after this method returns the offset will be equal to newLength.
If the present length of the file as returned by the length method is smaller than the newLength argument then the file will be extended.
In this case, the contents of the extended portion of the file are not defined. A closed random access file cannot perform input or output operations and cannot be reopened. Labels: core java , java IO tutorial. No comments :. Newer Post Older Post Home. Subscribe to: Post Comments Atom. Subscribe for Discounts and Updates Follow. Search This Blog. Interview Questions core java interview question data structure and algorithm 80 Coding Interview Question 75 interview questions 70 design patterns 35 SQL Interview Questions 34 object oriented programming 34 thread interview questions 30 spring interview questions 28 collections interview questions 25 database interview questions 16 servlet interview questions 15 Programming interview question 6 hibernate interview questions 6.
How to design a vending machine in Java? How HashMap works in Java? Why String is Immutable in Java? Translate This Blog. How to use Lock and ReentrantLock for Synchronizat How to solve FizzBuzz Problem in Java 8? Top 25 Vue. How to Clone a Collection in Java? Deep copy of Ar How to use Stream with List and Collection in Java The error and pragma Preprocessor Directives F.
The and Operators F. Predefined Symbolic Constants F. Assertions F. Class ATM G. Class Screen G. Class Keypad G. Class CashDispenser G. Class DepositSlot G. Class Account G. Class BankDatabase G. Class Transaction G. Class BalanceInquiry G. Class Withdrawal G. Class Deposit G. Wrap-Up Appendix H. Introduction H. Additional Diagram Types Appendix I. Resources I. Tutorials I. FAQs I. Newsgroups I. Compilers and Development Tools I.
Standard Template Library Appendix J. Introduction J.
0コメント