java save string in text file

Java
try (PrintWriter out = new PrintWriter("filename.txt")) {
    out.println(text);
}
Source

Also in Java: