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

voidsaveToFile(InputStream in, String fileName)
save To File
FileOutputStream fos = null;
BufferedInputStream bis = null;
int BUFFER_SIZE = 1024;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
bis = new BufferedInputStream(in);
fos = new FileOutputStream(fileName);
while ((size = bis.read(buf)) != -1)
...
voidsaveToFile(InputStream stream, File file)
save To File
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[BUF_SIZE];
int len;
while ((len = stream.read(buf)) != -1) {
    fos.write(buf, 0, len);
fos.close();
StringsaveToFile(String baseName, String extension, byte[] content)
Saves byte[] to new file.
String result;
File output = determineFilename(baseName, extension);
FileOutputStream target = null;
try {
    target = new FileOutputStream(output);
    target.write(content);
    result = output.getAbsolutePath();
} catch (Exception e) {
...
voidsaveToFile(String data, File file)
Save to file.
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(file);
    fos.write(data.getBytes());
} finally {
    if (fos != null)
        fos.close();
voidsaveToFile(String data, File file)
save To File
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(file);
    fos.write(data.getBytes());
} finally {
    if (fos != null)
        fos.close();
FilesaveToFile(String fileName, String fileCode, File dir, String fileExtention)
save To File
try {
    if (!dir.exists()) {
        dir.mkdirs();
} catch (Exception e) {
    e.printStackTrace();
FileOutputStream fos = null;
...
voidsaveToFile(String filePath, InputStream in)
save To File
FileOutputStream fos = null;
BufferedInputStream bis = null;
try {
    int BUFFER_SIZE = 1024;
    byte[] buf = new byte[BUFFER_SIZE];
    int size = 0;
    bis = new BufferedInputStream(in);
    fos = new FileOutputStream(filePath);
...
voidsaveToTextFile(String filename, byte[] text)
save To Text File
FileOutputStream out = new FileOutputStream(filename + ".ctron");
byte[] buffer = text;
out.write(buffer, 0, buffer.length);
voidSaveToZipSB(File file, String ZippedFile, StringBuilder sb)
Save To Zip SB
try {
    final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
    ZipEntry e = new ZipEntry(ZippedFile);
    out.putNextEntry(e);
    byte[] data = sb.toString().getBytes();
    out.write(data, 0, data.length);
    out.closeEntry();
    out.close();
...
voidsaveZip(String fileName, Map dataMap)
save Zip
try {
    FileOutputStream fos = new FileOutputStream(fileName);
    JarOutputStream jos = new JarOutputStream(fos);
    byte buf[] = new byte[256];
    if (dataMap != null) {
        Set<Entry<String, InputStream>> entrySet = dataMap.entrySet();
        int len = -1;
        for (Entry<String, InputStream> entry : entrySet) {
...