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

voidsaveFile(File f, InputStream stream)
saveFile Saves a given input stream to a specified file
OutputStream out = new FileOutputStream(f);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = stream.read(bytes)) != -1) {
    out.write(bytes, 0, read);
stream.close();
out.flush();
...
voidsaveFile(File f, String fileName, File desDir)
saveFile
InputStream stream = new FileInputStream(f);
OutputStream out = new FileOutputStream(desDir.getAbsolutePath() + File.separator + fileName);
int bytesRead = 0;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) {
    out.write(buffer, 0, bytesRead);
stream.close();
...
voidsaveFile(File f, String fileName, File desDir)
saveFile
InputStream stream = new FileInputStream(f);
OutputStream out = new FileOutputStream(desDir.getAbsolutePath() + File.separatorChar + fileName);
int bytesRead;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) {
    out.write(buffer, 0, bytesRead);
stream.close();
...
voidsaveFile(File file, byte[] contenido)
save File
try {
    RandomAccessFile lObjSalida = new RandomAccessFile(file, "rw");
    lObjSalida.write(contenido, 0, contenido.length);
    lObjSalida.close();
} catch (IOException e) {
    System.out.println("Error saving file at " + file + " " + e.getMessage());
    throw e;
voidsaveFile(File file, InputStream is)
save File
OutputStream os;
try {
    os = new BufferedOutputStream(new FileOutputStream(file));
} catch (IOException e) {
    throw new RuntimeException(e);
pipe(is, os);
voidsaveFile(File file, String fileName, String filesDirectory)
save File
FileInputStream in = null;
FileOutputStream out = null;
File dir = new File(filesDirectory);
if (!dir.exists())
    dir.mkdirs();
String targetPath = dir.getPath() + File.separator + fileName;
System.out.println("source file path ::" + file.getAbsolutePath());
System.out.println("saving file to ::" + targetPath);
...
voidsaveFile(File file, String savePath)
save File
FileInputStream inputStream = null;
ByteArrayOutputStream baos = null;
try {
    inputStream = new FileInputStream(file);
    baos = new ByteArrayOutputStream();
    OutputStream bos = new FileOutputStream(savePath);
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
...
voidsaveFile(final byte[] bytes, final File target)
save an array of bytes
if (!target.exists()) {
    try {
        if (!target.createNewFile()) {
            throw new IllegalArgumentException(
                    "Can't write to given target file: " + target.getAbsolutePath());
    } catch (final IOException e) {
        throw new IllegalArgumentException("Can't write to given target file: " + target.getAbsolutePath(),
...
booleansaveFile(final File file, final byte[] dataToSave)
save File
final FileOutputStream fos = new FileOutputStream(file);
fos.write(dataToSave);
fos.close();
return true;
voidsaveFile(final File file, final String contents, final String encoding)
Save the data, represented as a String to a file
saveFile(file, contents.getBytes(encoding));