Java Utililty Methods FileOutputStream Write

List of utility methods to do FileOutputStream Write

Description

The list of methods to do FileOutputStream Write are organized into topic(s).

Method

voidsaveToBinaryFile(File dest, byte[] data)
save To Binary File
FileOutputStream out = null;
try {
    out = new FileOutputStream(dest);
    out.write(data);
} finally {
    close(out);
voidsaveToDisc(final InputStream fileInputStream, final String fileUploadPath)
save To Disc
final OutputStream out = new FileOutputStream(new File(fileUploadPath));
int read = 0;
byte[] bytes = new byte[BUFFER_SIZE];
while ((read = fileInputStream.read(bytes)) != -1) {
    out.write(bytes, 0, read);
out.flush();
out.close();
...
voidsaveToDisk(InputStream is, String filename)
save primary conetent to local
FileOutputStream fos = new FileOutputStream(filename);
byte[] buf = new byte[1024];
int len = 0;
while ((len = is.read(buf)) > 0) {
    fos.write(buf, 0, len);
fos.flush();
fos.close();
...
voidsaveToDisk(String contents, String filename)
save To Disk
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(filename);
    fos.write(contents.getBytes(DEFAULT_CHARSET));
    fos.flush();
} finally {
    if (fos != null)
        fos.close();
...
voidsaveToEml(Message mail, File emlFile)
save To Eml
OutputStream os = null;
try {
    os = new FileOutputStream(emlFile);
    mail.writeTo(os);
} finally {
    if (os != null) {
        os.close();
booleansaveToFile(byte[] data, String filename)
save To File
OutputStream os = null;
ByteArrayInputStream bin = null;
try {
    if (data != null) {
        bin = new ByteArrayInputStream(data);
        os = new FileOutputStream(filename);
        byte[] bytes = new byte[1024];
        int c;
...
voidsaveToFile(File file, byte[] buffer)
Saves an array of bytes to a file in the file system.
FileOutputStream out = new FileOutputStream(file);
try {
    out.write(buffer);
} finally {
    out.close();
voidsaveToFile(final String file, final byte[] data, final boolean overwrite)
save byte array into a file
assertNotNull(file, "file");
assertNotNull(data, "data");
final File f = new File(file);
if (f.exists() && !overwrite) {
    throw new IllegalArgumentException("cannot overwrite file " + file);
FileOutputStream fos = null;
try {
...
voidsaveToFile(final String text, final File file)
save To File
final FileOutputStream os = new FileOutputStream(file);
try {
    os.write(text.getBytes(ENCODING));
    os.flush();
} finally {
    os.close();
voidsaveToFile(InputStream in, File dst)
saves content of src into dst
if (dst.exists())
    dst.delete();
dst.createNewFile();
OutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
...