All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atatctech.packages.basics.Basics Maven / Gradle / Ivy

Go to download

The most suitable text language for documentation. Native support for Markdown and HTML.

There is a newer version: 1.0.4
Show newest version
package com.atatctech.packages.basics;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;

public class Basics {
    public static class NativeHandler {
        public static String readFile(String filename) throws IOException {
            return readFile(new File(filename));
        }

        public static String readFile(File file) throws IOException {
            return new String(Files.readAllBytes(file.toPath()));
        }

        public static boolean writeFile(String filename, String content, boolean append) {
            try (FileWriter fileWriter = new FileWriter(filename, append)) {
                fileWriter.write(content);
                return true;
            } catch (IOException ignored) {
                return false;
            }
        }

        public static boolean writeFile(String filename, String content) {
            return writeFile(filename, content, false);
        }

        public static boolean writeFile(File file, String content, boolean append) {
            try (FileWriter fileWriter = new FileWriter(file, append)) {
                fileWriter.write(content);
                return true;
            } catch (IOException ignored) {
                return false;
            }
        }

        public static boolean writeFile(File file, String content) {
            return writeFile(file, content, false);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy