How to design a Saved/Printed File?

I have made a basic statistics analysis program which scans a .txt file for test scores and then maps the scores to a table. The program can then run a data correlation algorithm and will highlight outliers in the scores, which are kept in a table.

I have a method called writeFile() that can save a report to a .txt file, which works similar to System.out.println().

    public void writeFile(File file, String fileName)
    {
        try
            {
            PrintWriter writer = new PrintWriter(file + "//" + fileName + ".txt", "UTF-8);

            //This is where all of the report info is added    
            writer.println("report data");
            writer.println("more report data");

            writer.close();
            }
        catch(Exception e)
            {
            System.out.println("could not create file");
            }
    }

And I have found that I can use table.print() to print out the formatted table

I am trying to design a custom output, so that I can save and print a formatted and designed file output, similar to what you can do in Microsoft Word, but hard coded in. From what I have found while researching, a .txt file can contain no formatting. Is there a format that will allow me more control over the design of the report? I would like to include the table and text, as well as have control over font, color, spacing, etc…

Also is there a way to customize what you are printing, such as a specified file?

From what I have found while researching, a .txt file can contain no formatting.

You are correct.

Is there a format that will allow me more control over the design of the report?

Yes, several have been mentioned in the comments, but HTML seems to match your needs. You can use HTML with CSS to do all of the formatting you want. As a bonus, you can make the report pop open in a web browser (any web browser!) for your user to see.

The downside of HTML is that while it is pretty easy (and extremely well documented in web resources), it’s more user-friendly for display than for storage. So if you mostly want to show a report, and don’t care as much about the user saving, archiving, transporting, or printing it, HTML is an excellent choice.

However, if it’s very important to do those things with a report, and it’s OK to make the user deal with a PDF, you might prefer PDF format, which is more complicated to generate programmatically, and doesn’t provide as many delightful display options, but which excels at being stored and printed.