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(String directoryPath, String filename, byte[] bytes)
Write a file containing the data in an array of bytes.
try {
    FileOutputStream os = new FileOutputStream(new File(directoryPath, filename));
    BufferedOutputStream bos = new BufferedOutputStream(os);
    bos.write(bytes, 0, bytes.length);
    bos.flush();
    os.flush();
    bos.close();
    os.close();
...
voidwriteFile(String f, String s)
write File
OutputStreamWriter out = null;
try {
    out = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
    out.write(s);
} finally {
    try {
        if (out != null)
            out.close();
...
voidwriteFile(String file, byte[]... data)
write File
try (FileOutputStream fos = new FileOutputStream(file)) {
    for (byte[] d : data) {
        fos.write(d);
} catch (IOException ex) {
voidwriteFile(String file, byte[]... data)
write File
try (FileOutputStream fos = new FileOutputStream(file)) {
    for (byte[] d : data) {
        fos.write(d);
} catch (IOException ex) {
OutputStreamwriteFile(String fileName)
Writes the file corresponding to the passed file name.
if (fileName == null)
    throw new IllegalArgumentException("No file name specified.");
File f = new File(fileName);
FileOutputStream out = null;
try {
    out = new FileOutputStream(f);
    return new BufferedOutputStream(out);
} catch (Exception e) {
...
voidwriteFile(String fileOutput, byte[] data)
write File
OutputStream outputStream = new FileOutputStream(fileOutput);
try {
    outputStream.write(data);
} finally {
    outputStream.close();
voidwriteFile(String filePath, byte[] bytes)
Writes given bytes to the file
try (FileOutputStream fos = new FileOutputStream(filePath)) {
    fos.write(bytes);
} catch (IOException ex) {
    System.out.println("Error writing file: " + ex.toString());
voidwriteFile(String filePath, Object obj)
write File
FileOutputStream fop = null;
File file;
String content = obj.toString();
try {
    file = new File(filePath);
    fop = new FileOutputStream(file);
    if (!file.exists()) {
        file.createNewFile();
...
voidwriteFile(String filePathName, Object obj)
write File
ObjectOutputStream oout = null;
File file = new File(filePathName);
try {
    if (!file.exists()) {
        file.createNewFile();
    oout = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    oout.writeObject(obj);
...
voidwriteFile(String p_filename, String p_buffer)
Write a TEXT file
FileOutputStream os = null;
try {
    os = new FileOutputStream(p_filename);
    if (p_buffer != null) {
        os.write(p_buffer.getBytes());
    os.close();
    os = null;
...