Java--Save byte[] Data

Source: Internet
Author: User

Create the file, save the byte data directly to the private randomaccessfile file_test;try {File File = new file ("/sdcard/data.yuv");  The suffix itself defines if (File.exists ()) File.delete (); file_test = new Randomaccessfile (file, "RW");   Readable/writable} catch (Exception ex) {LOG.V ("System.out", ex.tostring ());} Call try {    file_test.write (bytesdata);} catch (IOException e) {    e.printstacktrace ();}


* Randomaccessfile is a class of IO packets, but it is a faction that inherits directly from Object . You can only manipulate files, and you can read and write to them.
* When the mode is R, when the file does not exist, it will report an exception, when the mode is RW, when the file does not exist, it will create the file itself, when the file already exists, will not overwrite the original file.

* Randomaccessfile has a powerful file read and write function, its internal is a large byte[], can be through Seek (), Getfilepointer () and other methods of operation of the pointer, easy to write and read data. You can also perform direct read and write operations on basic data types.


Randomaccessfile does not belong to the InputStream and OutputStream class systems. In fact, in addition to implementing the Datainput and DataOutput interfaces (both DataInputStream and DataOutputStream implement both interfaces), it has nothing to do with these two classes, Do not even use any of the features that already exist in the InputStream and OutputStream classes; it is a completely independent class, and all methods (most of them belong to itself) are written from scratch. This may be because randomaccessfile can move back and forth within a file, so its behavior is fundamentally different from other I/O classes. In summary, it is a separate class that inherits directly from object.

Basically, the way Randomaccessfile works is to combine DataInputStream and dataoutputstream, plus some of its own methods, such as the getfilepointer of positioning (), The Seek () to be moved in the file, and the number of bytes to determine the length (), skipbytes () of the file size skipped. In addition, its constructor has a parameter that indicates whether to open the file as read-only ("R") or read-write ("RW") (fopen () of C). It does not support write-only files.

Java--Save byte[] Data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.