Check this article. There are some ways to write something to text file using Java.
Example from Baeldung:
String str = "Hello";
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
writer.write(str);
writer.close();
Is it what you are looking for?
CLICK HERE to find out more related problems solutions.