com.almworks.util.FileUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of generator-maven-plugin
Show all versions of generator-maven-plugin
Maven plugin to generate java code from templates
The newest version!
package com.almworks.util;
import java.io.*;
public class FileUtil {
public static void writeFile(File file, String content, String charsetName) throws IOException {
byte[] bytes = content.getBytes(charsetName);
try (OutputStream stream = new FileOutputStream(file)) {
stream.write(bytes);
}
}
public static String readFile(File file, String charsetName) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
try (InputStream stream = new FileInputStream(file)) {
int read;
while ((read = stream.read(buffer)) >= 0) {
bytes.write(buffer, 0, read);
}
}
return new String(bytes.toByteArray(), charsetName);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy