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

voidsaveBytesToFile(byte[] str, File file)
save Bytes To File
FileOutputStream fos = new FileOutputStream(file);
fos.write(str);
fos.flush();
fos.close();
voidsaveBytesToFile(String filepath, byte[] data)
save Bytes To File
ByteArrayInputStream is = new ByteArrayInputStream(data);
java.io.FileOutputStream fos = new java.io.FileOutputStream(new File(filepath));
while (is.available() > 0) {
    fos.write(is.read());
fos.close();
is.close();
voidsaveCertReqToFile(String certReq, String fileLocation)
Save a certificate request in specific location
FileOutputStream os = new FileOutputStream(fileLocation);
os.write(certReq.getBytes());
os.close();
booleansaveColorTable(final float[][] table, final File file)
Saves the given color table into the specified file.
if (file == null || table == null || table.length != 3)
    return false;
final int len = LUT_LEN / 3;
final int[] b = new int[LUT_LEN];
int count = 0;
for (int i = 0; i < 3; i++) {
    if (table[i].length != len)
        return false;
...
longsaveContentToFile(DataHandler content, File outFile)
Saves the specified content to the specified file
long size = 0;
byte[] buffer = new byte[1024];
try (InputStream is = content.getInputStream()) {
    try (OutputStream outStream = new FileOutputStream(outFile)) {
        for (int readBytes; (readBytes = is.read(buffer, 0, buffer.length)) > 0;) {
            size += readBytes;
            outStream.write(buffer, 0, readBytes);
return size;
booleansaveData(byte[] data, String PATH, String fileName)
save Data
boolean ok = false;
if (data != null) {
    try {
        FileOutputStream fos;
        File outputDir = new File(PATH);
        File saveFile = new File(outputDir, fileName);
        fos = new FileOutputStream(saveFile);
        fos.write(data);
...
booleansaveDataToFile(String filePath, byte[] data)
save Data To File
FileOutputStream f = null;
try {
    f = new FileOutputStream(filePath);
    f.write(data);
} catch (IOException e) {
    return false;
return true;
...
voidsaveDownloadedFile(InputStream is, String destination)
Saves an input stream as file
BufferedOutputStream out = null;
try {
    out = new BufferedOutputStream(new FileOutputStream(new File(destination)));
    ByteStreams.copy(is, out);
} finally {
    is.close();
    if (out != null) {
        out.close();
...
voidsaveEntry(String destPath, ZipEntry target, ZipFile zf)
save Entry
InputStream is = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
    File file = new File(destPath + "/" + target.getName());
    if (target.isDirectory()) {
        file.mkdirs();
...
StringsaveFile(byte[] fileData, String outputDir, String fileName)
save File
String path = outputDir + "/" + fileName;
File outFile = new File(path);
if (!outFile.getParentFile().exists()) {
    outFile.getParentFile().mkdirs();
if (!outFile.exists()) {
    outFile.createNewFile();
OutputStream os = new FileOutputStream(outFile);
os.write(fileData);
os.close();
return path;