How to write to a text file in Java?

I would suggest you to use PrintWriter class to write to a text file the same way you'll print to a socket. In the below example object out is created so later on out.println("whatever") can be invoked.

PrintWriter out = new PrintWriter(new FileOutputStream("received.txt"));

No comments: