Java Utililty Methods Text File Write

List of utility methods to do Text File Write

Description

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

Method

voidwriteString(String fileName, String str)
This writes a string into a given file.
FileOutputStream os = new FileOutputStream(fileName);
os.write(str.getBytes());
os.close();
voidwriteString(String filePath, boolean append, String content, String encoding)
write String
writeBytes(filePath, append, content.getBytes(encoding));
voidwriteString(String filePath, String content)
Write a string into a file
writeString(filePath, content, false);
voidwriteString(String par0)
write String
try {
    dataOS.writeUTF(par0);
} catch (IOException ex) {
    ex.printStackTrace();
voidwriteString(String path, String key, String value)
Writes a registry key to the Windows registry (only string type, REG_SZ).
Objects.requireNonNull(path, value);
List<String> command = new ArrayList<>();
command.add("reg");
command.add("add");
command.add(path);
if (key != null) {
    command.add("/v");
    command.add(key);
...
voidwriteString(String path, String str)
write String
BufferedWriter out = null;
try {
    File f = new File(path);
    File parent = f.getParentFile();
    if (!parent.exists())
        parent.mkdirs();
    out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "utf-8"));
    out.write(str);
...
voidwriteString(String path, String str, boolean append)
write String
FileWriter out = null;
try {
    out = new FileWriter(path, append);
    out.write(str);
} catch (IOException e) {
    throw new RuntimeException("Could not write String[" + path + "]", e);
} finally {
    close(out);
...
voidwriteString(String s, File output, String encoding)
Writes a string to a file, using the given encoding.
BufferedReader buffer = new BufferedReader(new StringReader(s));
FileOutputStream fos = new FileOutputStream(output);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, encoding));
for (String nextLine; (nextLine = buffer.readLine()) != null;)
    writer.println(nextLine);
writer.close();
buffer.close();
voidwriteString(String string, ObjectOutput out)
write String
if (string == null) {
    out.writeByte(NULL);
} else {
    out.writeByte(NOTNULL);
    out.writeUTF(string);
byte[]writeString(String value)
Writes a string value to the stream using UTF-8 encoding.
ByteArrayOutputStream bout = new ByteArrayOutputStream();
if (value == null) {
    bout.write((byte) 'N');
    return bout.toByteArray();
int length = value.length();
int strOffset = 0;
while (length > 0x8000) {
...