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

voidsaveIntArrayToFile(int[] array, File file)
save Int Array To File
try {
    FileOutputStream fos = new FileOutputStream(file);
    DataOutputStream dos = new DataOutputStream(fos);
    for (int i : array) {
        dos.writeInt(i);
    dos.close();
    fos.close();
...
voidsaveKeyToFile(String key)
save Key To File
try {
    FileOutputStream out = new FileOutputStream("/home/junior/antinsa.keystore");
    BufferedReader c = new BufferedReader(new StringReader(key));
    int b;
    while ((b = c.read()) > -1) {
        out.write(b);
    c.close();
...
voidsaveLongList(String file, Collection c, boolean append)
save Long List
File p = new File(file).getParentFile();
if (p != null)
    p.mkdirs();
FileOutputStream fout = new FileOutputStream(file, append);
try {
    for (Long subjectID : c) {
        fout.write((subjectID + "\n").getBytes());
} finally {
    fout.close();
booleansaveProxyClass(String path, String proxyClassName, Class[] interfaces)
Save proxy class to path
if (proxyClassName == null || path == null) {
    return false;
byte[] classFile = ProxyGenerator.generateProxyClass(proxyClassName, interfaces);
FileOutputStream out = null;
try {
    out = new FileOutputStream(path);
    out.write(classFile);
...
voidsaveResouce(String resourceName, String outputFile)
save Resouce
InputStream input = resourceName.getClass().getResourceAsStream(resourceName);
OutputStream output;
output = new FileOutputStream(outputFile);
writeFile(input, output);
output.flush();
output.close();
voidsaveStream(InputStream is, File output)
save Stream
byte[] buf = new byte[1024];
int cnt;
try (FileOutputStream fos = new FileOutputStream(output)) {
    while ((cnt = is.read(buf)) > 0) {
        fos.write(buf, 0, cnt);
        fos.flush();
voidsaveStream(InputStream stream, File targetFile)
Saves the data from an InputStream into a file.
BufferedOutputStream out = null;
try {
    out = new BufferedOutputStream(new FileOutputStream(targetFile), 0x4000);
    pipeStreams(stream, out);
} finally {
    try {
        if (out != null) {
            out.close();
...
voidsaveStreamToFile(InputStream in, File outFile)
save Stream To File
FileOutputStream out = null;
try {
    out = new FileOutputStream(outFile);
    byte[] buf = new byte[4096];
    int bytes_read;
    while ((bytes_read = in.read(buf)) != -1)
        out.write(buf, 0, bytes_read);
} finally {
...
booleansaveStreamToFile(InputStream is, File destFile)
save Stream To File
FileOutputStream fos = new FileOutputStream(destFile);
int readLen = 0;
byte[] buf = new byte[1024];
while ((readLen = is.read(buf)) != -1) {
    System.out.println(readLen);
    fos.write(buf, 0, readLen);
fos.flush();
...
voidsaveStringIntoFile(File file, String contents)
save a string into a file, file does not have to exist
try {
    writeStringToFile(file, contents, "ISO-8859-1");
} catch (IOException ioe) {
    throw new RuntimeException(ioe);