Skip to content

Instantly share code, notes, and snippets.

@oofnivek
Created January 11, 2024 12:31
Show Gist options
  • Save oofnivek/e42c064c305c57a5c55f59c07b6e1bb1 to your computer and use it in GitHub Desktop.
Save oofnivek/e42c064c305c57a5c55f59c07b6e1bb1 to your computer and use it in GitHub Desktop.
Write string contents to file
package org.example;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
String content = "hello world";
try {
Files.write(Paths.get("output.txt"), content.getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment