Java Utililty Methods File Write

List of utility methods to do File Write

Description

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

Method

voidfileWrite(String filename, byte[] ba)
file Write
FileOutputStream fos = new FileOutputStream(filename);
fos.write(ba);
fos.close();
voidfileWrite(String fileName, String str)
file Write
File file = new File(fileName);
FileOutputStream fopstream = null;
try {
    fopstream = new FileOutputStream(file);
    fopstream.write(str.getBytes());
} catch (Exception e1) {
    e1.printStackTrace();
} finally {
...
voidfileWrite(String filePath, String data)
file Write
BufferedWriter out = null;
try {
    out = new BufferedWriter(new FileWriter(filePath));
    out.write(data);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    out.close();
...
voidfileWrite(String filePath, String fileName, String content)
file Write
if (filePath.endsWith("/")) {
    filePath = filePath.substring(0, filePath.length() - 1);
File dest = new File(filePath);
if (!dest.exists()) {
    dest.mkdirs();
try {
...
intfileWrite(String path, int format, String content, Object bytesObj)
file Write
byte[] bytes = null;
try {
    switch (format) {
    case 0:
        bytes = (byte[]) bytesObj;
        break;
    case 1: 
        bytes = content.getBytes("UTF-8");
...
booleanfileWrite(String[] text, File file)
Writes an array of String to specified text file.
try {
    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    PrintWriter writeOut = new PrintWriter(out);
    for (int i = 0; i < text.length; i++) {
        writeOut.println(text[i]);
    writeOut.close();
    return true;
...
longfileWriteOut(InputStream in, String outPath)
file Write Out
byte[] buf = new byte[1024];
int length = 0;
long fileSize = 0;
OutputStream out = null;
try {
    out = new BufferedOutputStream(new FileOutputStream(outPath));
    while ((length = in.read(buf)) > 0) {
        fileSize += length;
...
voidfileWriter(int startpt, int letter)
file Writer
System.out.println("Start point: " + (char) startpt);
System.out.println("End point: " + (char) 55203);
String filename = (char) letter + "";
System.out.println("Writing to file: " + filename);
ArrayList letters = lastLetterGen(startpt);
try {
    PrintWriter pr = new PrintWriter(filename);
    for (int i = 0; i < letters.size(); i++) {
...
voidfileWriter(String outfile, String contents, boolean append)
Synopsis [ ] String to file, with append to file true/false option
try {
    BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outfile), append)); 
    bw.write(contents);
    bw.close();
} catch (Exception e) {
voidfileWriteString(String filePath, String strWrite, boolean append)
file Write String
File f = new File(filePath);
Writer out = null;
try {
    out = new FileWriter(f, append);
    out.write(strWrite);
    out.close();
} catch (IOException e) {
    e.printStackTrace();
...