public final class BinaryIO
extends java.lang.Object
A collection of static methods for reading and writing binary files.
Please don't use them for text files (besides copy method):
use TextIO class instead.
Methods of this class throw NullPointerException
if one of the arguments is null.
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(java.io.File source,
java.io.File target)
Fully copies the source file into the target file name.
|
static java.io.Serializable |
deserialize(java.io.File file) |
static java.io.Serializable |
deserialize(java.io.InputStream inputStream,
boolean closeStream) |
static byte[] |
read(java.io.File file)
Reads all bytes of the given file and returns it as an array of bytes.
|
static byte[] |
read(java.io.InputStream inputStream,
boolean closeStream)
Reads all bytes from the current position of the input stream
until the end of this stream and returns them as an array of bytes.
|
static void |
serialize(java.io.File file,
java.io.Serializable data) |
static void |
write(java.io.File file,
byte[] data)
Saves the bytes passed in the
data argument in the given file. |
static void |
writeOrDelete(java.io.File file,
byte[] data)
|
public static byte[] read(java.io.InputStream inputStream,
boolean closeStream)
throws java.io.IOException
Class.getResourceAsStream method is used to
access such resources.inputStream - the input stream (will be read until its end)closeStream - if true, the input stream will be closed for sure
before ending this methodjava.io.IOException - if an I/O error occurspublic static byte[] read(java.io.File file)
throws java.io.IOException
file - the file to be readjava.io.IOException - if an I/O error occurspublic static void write(java.io.File file,
byte[] data)
throws java.io.IOException
data argument in the given file.
The file is fully rewritten and will contain this bytes only.
In a case of I/O errors, the file will be attempted to be deleted.file - the file to be saveddata - the bytes saved in the filejava.io.IOException - if an I/O error occurspublic static void writeOrDelete(java.io.File file,
byte[] data)
throws java.io.IOException
file - the file to be saveddata - the bytes saved in the filejava.io.IOException - if an I/O error occurspublic static void copy(java.io.File source,
java.io.File target)
throws java.io.IOException
source - the source file to be copiedtarget - the created copy of the source filejava.io.IOException - if an I/O error occurspublic static java.io.Serializable deserialize(java.io.InputStream inputStream,
boolean closeStream)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic static java.io.Serializable deserialize(java.io.File file)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic static void serialize(java.io.File file,
java.io.Serializable data)
throws java.io.IOException
java.io.IOException