Java Utililty Methods FileOutputStream Create

List of utility methods to do FileOutputStream Create

Description

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

Method

voidwriteFile(final String filename, final byte[] data)
Writes data to a file.
if (filename.equals("-")) {
    System.out.write(data);
    return;
try (final OutputStream stream = new FileOutputStream(filename)) {
    stream.write(data);
voidwriteFile(final String fileNamePath, final byte[] daten)
write File
FileOutputStream output = null;
try {
    output = new FileOutputStream(fileNamePath);
    output.write(daten);
} finally {
    if (output != null) {
        output.close();
voidwriteFile(InputStream in, File file)
Saves an Input Stream to a file.
FileOutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int len = in.read(buffer);
while (len != -1) {
    out.write(buffer, 0, len);
    len = in.read(buffer);
out.close();
...
voidwriteFile(InputStream inputFile, String path, String fullFileName)
Writes an file in a specific folder in the web server.
File file = new File(path + fullFileName);
OutputStream outputFile = new FileOutputStream(file);
byte buf[] = new byte[1024];
int length;
while ((length = inputFile.read(buf)) > 0) {
    outputFile.write(buf, 0, length);
inputFile.close();
...
FilewriteFile(InputStream inputStream, String filename, long lastModified)
Write a file to disk
File file = new File(filename);
file.createNewFile();
OutputStream out = new FileOutputStream(file);
byte[] bytes = new byte[4096];
for (int len; (len = inputStream.read(bytes)) > 0;) {
    out.write(bytes, 0, len);
out.flush();
...
voidwriteFile(InputStream is, File file)
write File
file.getParentFile().mkdirs();
try (FileOutputStream fos = new FileOutputStream(file)) {
    final byte data[] = new byte[1024];
    int count;
    while ((count = is.read(data, 0, 1024)) != -1) {
        fos.write(data, 0, count);
voidwriteFile(InputStream is, File outFile)
write File
BufferedOutputStream bos = null;
try {
    bos = new BufferedOutputStream(new FileOutputStream(outFile));
    byte[] buffer = new byte[4096];
    int len;
    BufferedInputStream bis = new BufferedInputStream(is);
    while ((len = bis.read(buffer)) != -1) {
        bos.write(buffer, 0, len);
...
voidwriteFile(InputStream srcStream, File destFile)
write File
File testFile = destFile.getParentFile();
if (!testFile.exists())
    testFile.mkdirs();
FileOutputStream destStream = new FileOutputStream(destFile);
byte[] buf = new byte[65535];
int bytesRead;
while (true) {
    bytesRead = srcStream.read(buf);
...
voidwriteFile(InputStream stream, File to)
Create a file with the contents of this data stream.
if (to.exists()) {
    throw new IOException("File '" + to.getAbsolutePath() + "' already exists.");
File parent = to.getParentFile();
if (!parent.exists()) {
    parent.mkdirs();
    if (!parent.exists()) {
        throw new IOException("Can't create parent directory for '" + to.getAbsolutePath() + "'");
...
voidwriteFile(List data, String filename)
write File
try (FileOutputStream file = new FileOutputStream(filename)) {
    byte[] bytes = new byte[data.size()];
    for (int i = 0; i < bytes.length; i++)
        bytes[i] = data.get(i);
    file.write(bytes);
} catch (IOException e) {
    throw new RuntimeException(e);