Java swing display text file project file

broken image
broken image

In step 4, once the output is completed, you close the output files by using the method close. In step 3, you store the output in the file oceans.txt. PrintWriter out = new PrintWriter('oceans.txt') // Step 2 In step 2, you create the PrintWriter object out and associates it with the file hello.txt. In step 1, you import the package to use PrintWriter class. Now discuss the above prgram step by step: Write the name of four oceans to the file Public static void main(String args) throws IOException The following program writes the name of four oceans to the text file.

broken image
broken image

The class PrintWriter has the familiar print() and println() methods we have been using for writing to the console. The simplest way to write text to a file requires us to use PrintWriter class from the standard package java.io.

broken image