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

BooleanwriteFile(String path, byte[] contents)
write File
Boolean success = false;
try {
    File outputfile = new File(path);
    FileOutputStream fos = new FileOutputStream(outputfile);
    fos.write(contents);
    fos.flush();
    fos.close();
    success = true;
...
booleanwriteFile(String path, byte[] data)
Write whole data to a file.
OutputStream os = null;
try {
    os = new FileOutputStream(path);
    os.write(data);
} catch (IOException e) {
    return false;
} finally {
    try {
...
voidwriteFile(String path, Properties store, String comment)
Writes data of a Properties object to a properties file.
checkNullReference(path, store);
File file = new File(path);
File topDir = file.getParentFile();
if (topDir != null && !topDir.exists()) {
    topDir.mkdirs();
FileOutputStream fos = new FileOutputStream(file);
store.store(fos, comment);
...
voidwriteFile(ZipEntry entry, ZipFile zipFile, File file)
write File
if (!buildDirectory(file.getParentFile())) {
    throw new IOException("Could not create directory: " + file.getParentFile());
if (!entry.isDirectory()) {
    copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(file)));
} else {
    if (!buildDirectory(file)) {
        throw new IOException("Could not create directory: " + file);
...
StringwriteFile0(File file, CharSequence content, Iterable lines)
write File
PrintWriter out = null;
try {
    out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
    if (content != null) {
        out.print(content);
    } else {
        for (Object line : lines) {
            out.print(line);
...
voidwriteFileAsBytes(String fullPath, byte[] bytes)
Write an array of bytes to a file.
OutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(fullPath));
InputStream inputStream = new ByteArrayInputStream(bytes);
int token = -1;
while ((token = inputStream.read()) != -1) {
    bufferedOutputStream.write(token);
bufferedOutputStream.flush();
bufferedOutputStream.close();
...
voidwriteFileAsString(final File filePath, final String output, final String charset)
write File As String
final OutputStreamWriter osw = charset == null
        ? new OutputStreamWriter(new FileOutputStream(filePath, false))
        : new OutputStreamWriter(new FileOutputStream(filePath, false), charset);
osw.write(output);
osw.flush();
osw.close();
voidwriteFileAsString(String filename, String contents)
Write a String to disk using the specified filename and the default encoding.
writeFileAsString(filename, contents, null);
voidwriteFileBinary(String filename, byte[]... dataArrays)
write File Binary
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
for (byte[] data : dataArrays) {
    dos.write(data);
dos.flush();
dos.close();
voidwriteFileByBytes(String content, String filename)
write File By Bytes
File file = new java.io.File(filename);
OutputStream out = null;
try {
    out = new FileOutputStream(file, true);
    byte[] bytes = content.getBytes();
    out.write(bytes);
} catch (Exception e) {
    e.printStackTrace();
...