Java Utililty Methods OutputStream Write

List of utility methods to do OutputStream Write

Description

The list of methods to do OutputStream Write are organized into topic(s).

Method

voidcopyFile(File fromFile, File toFile)
copy File
System.out.println("cp " + fromFile.getName() + " " + toFile.getName());
Runtime.getRuntime().exec("cp " + fromFile.getAbsolutePath() + " " + toFile.getAbsolutePath());
voidcopyFile(final InputStream in, final OutputStream out, final int size)
Copy a file from one location to another
try {
    final byte[] buffer = new byte[size];
    int length;
    while ((length = in.read(buffer)) > 0)
        out.write(buffer, 0, length);
} catch (final Exception e) {
    e.printStackTrace();
} finally {
...
voidcopyFile(InputStream in, OutputStream out)
copy File
byte[] buffer = new byte[10240];
int len;
while ((len = in.read(buffer)) >= 0) {
    out.write(buffer, 0, len);
intcopyFile(InputStream in, OutputStream out, boolean close)
copy File
int size = 0;
int b = in.read();
while (b != -1) {
    size++;
    out.write(b);
    b = in.read();
in.close();
...
voidcopyFile(InputStream inputStream, OutputStream outputStream)
Copies a file from the given streams.
byte[] buf = new byte[1024];
int i = 0;
while ((i = inputStream.read(buf)) != -1) {
    outputStream.write(buf, 0, i);
voidcopyFile(OutputStream os, InputStream is)
Copies the inputstream to the output stream.
byte[] buf = new byte[8192];
int sz;
while (0 < (sz = is.read(buf)))
    os.write(buf, 0, sz);
voidcopyFile(String fileName, String newFileName)
copy File
Files.copy(new File(fileName), new File(newFileName));
voidcopyFilePermissions(File source, File target)
Sets the file permissions of the given source file on the given target file.
if (source.canRead()) {
    target.setReadable(true, false);
} else {
    target.setReadable(false, false);
if (source.canWrite()) {
    target.setWritable(true, false);
} else {
...
voidserialize(java.io.Serializable serializable, java.io.ObjectOutputStream oos)
serialize
try {
    oos.writeObject(serializable);
} catch (java.io.IOException ioe) {
    throw new RuntimeException(ioe);
voidserialize(Object o, OutputStream out)
Serializes the given object to the given output stream.
ObjectOutputStream oout = new ObjectOutputStream(out);
try {
    oout.writeObject(o);
} finally {
    if (oout != null) {
        oout.close();