Java Utililty Methods Text File Save

List of utility methods to do Text File Save

Description

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

Method

voidserialize(final File folder, final String content, final String fileName)
Serialize a content into a targeted file, checking that the parent directory exists.
if (!folder.exists()) {
    folder.mkdirs();
final File output = new File(folder, fileName);
FileWriter writer = null;
try {
    writer = new FileWriter(output);
    writer.write(content);
...
voidsetText(File file, String text)
set Text
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
bw.write(text, 0, text.length());
bw.flush();
bw.close();
voidwriteFile(ArrayList lines, String dest_path)
write File
FileWriter writer;
try {
    writer = new FileWriter(dest_path);
    for (String str : lines) {
        writer.write(str);
    writer.close();
} catch (IOException e) {
...
voidwriteFile(Collection emailTree, String destFile)
write File
try {
    FileWriter fw = new FileWriter(new File(destFile));
    BufferedWriter bw = new BufferedWriter(fw);
    for (String email : emailTree) {
        bw.write(email + "\n");
    bw.flush();
    bw.close();
...
voidwriteFile(File destinationFile, String contents, String encoding)
Writes given contents to destination file.
OutputStream stream = new BufferedOutputStream(new FileOutputStream(destinationFile));
stream.write(contents.getBytes(encoding));
stream.close();
voidwriteFile(File outputDirectory, String fileName, String source)
write File
File path = new File(outputDirectory.getAbsolutePath());
if (!path.exists()) {
    path.mkdirs();
File file = new File(path, fileName);
if (!file.exists()) {
    file.createNewFile();
System.out.println("Generating: " + file.getAbsolutePath());
try (FileOutputStream fos = new FileOutputStream(file)) {
    fos.write(source.trim().getBytes());
} catch (FileNotFoundException e) {
    e.printStackTrace();
voidwriteFile(File outputFile, ArrayList sortedLines, String lineSeparator)
write File
BufferedWriter out = null;
try {
    out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "US-ASCII"));
    for (String line : sortedLines) {
        out.write(line.replaceAll("\\\\[\n\r]+", "\\\\" + lineSeparator));
        out.write(lineSeparator);
} finally {
...
voidwriteFile(File outputFile, String text)
Writes the given text string into a file
Writer writer;
try {
    writer = new FileWriter(outputFile);
} catch (IOException e) {
    throw new Exception("Couldn't create writer", e);
try {
    writer.write(text);
...
voidwriteFile(File outputFolder, String fileName, String content)
write File
FileWriter outputFileReader = new FileWriter(new File(outputFolder, fileName));
BufferedWriter outputStream = new BufferedWriter(outputFileReader);
outputStream.write(content);
outputStream.close();
voidwriteFile(File path, File file, String content)
Write content to file using BufferedWriter.
try {
    if (!path.isDirectory()) {
        path.mkdir();
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write(content);
    writer.close();
} catch (IOException e) {
...