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

voidwriteFile(String path, String fileName, String data)
write File
createPath(path);
String fullPath = path + fileName;
File file = new File(fullPath);
if (!file.exists()) {
    file.createNewFile();
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
bufferedWriter.write(data);
...
voidwriteFile(String path, String text)
write File
Writer out = null;
try {
    out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"));
    out.write(text);
} catch (FileNotFoundException e) {
} finally {
    if (out != null)
        out.close();
...
voidwriteFile(String path, String text)
write File
writeFile(new File(path), text, false);
voidwriteFile(String path, String text, boolean orverWite)
write File
try {
    String oldText = "";
    if (!orverWite) {
        oldText = readFile(path);
    FileOutputStream fos = new FileOutputStream(path);
    Writer out = new OutputStreamWriter(fos, "UTF-8");
    out.write(oldText + text);
...
voidwriteFile(String path, Vector contents)
Write a Vector of lines to a file.
BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter(path));
    for (String line : contents)
        writer.write(line + '\n');
} catch (Exception ex) {
    System.err.println(ex);
} finally {
...
voidwriteFile(String pContent, String pPath)
write File
File file = new File(pPath);
FileWriter fstream;
try {
    fstream = new FileWriter(file);
    try (BufferedWriter out = new BufferedWriter(fstream)) {
        out.write(pContent);
} catch (IOException e) {
...
voidwriteFile(String ruta, String nombre, byte[] archivo)
write File
try {
    FileOutputStream file = null;
    File onlyCreateDirectory = null;
    onlyCreateDirectory = new File(ruta);
    onlyCreateDirectory.mkdirs();
    file = new FileOutputStream(ruta + nombre);
    file.write(archivo);
    file.flush();
...
booleanWriteFile(String sFileName, String content)
Write content to file
FileWriter fw = null;
try {
    fw = new FileWriter(sFileName, true);
    fw.write(content);
    fw.close();
} catch (IOException e) {
    e.printStackTrace();
    return false;
...
voidwriteFile(String sFileName, String sContent)
Writes a String into a given File.
FileOutputStream fos = new FileOutputStream(sFileName);
for (int i = 0; i < sContent.length(); i++) {
    fos.write(sContent.charAt(i));
fos.close();
voidwriteFile(String sName, String data, String encoding)
write File
File file = new File(sName);
try (PrintWriter out = openForWriting(file, encoding)) {
    out.print(data);