
/**
 * This class demonstrates one of many ways to write to a text file.
 * 
 * @author: Michael Pell, of Solutions Plus, Inc.
 */
public class WriteToTextFile{

public WriteToTextFile() {
	super();
}
/**
 * Starts the application.
 * Saves text to a file
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args)
{
/*
Requested output to look like:
Title XXXXXX
Date  XX/XX/XXXX
support alg1 alg2........algn
2        20s  48s........ 34s
5        31s  123s........37s
34       12s  48s........35s
44       29s  23s........123s


Actual output of this method looks like:

Title XXXXXXXXX 
Feb 21, 2000
 
support alg1 alg2........algn
2 20 48s
5 31 123s
34 12 48s
44 29 123s


You can use either Vectors or arrays.
To get the output text formatted the way you want, you just need to write some additional
code to get the columns aligned. This could be done inside the FOR loop.
How you write it will depend on the fonts you use to print the file with,
assuming you want to print it.
Please let me know if you have any additional questions; mjpell@sol-plus.com

*/
	try
	{
		java.io.File file = new java.io.File("C:\\temp\\output.txt");
		java.io.PrintWriter printWriter = new java.io.PrintWriter(new java.io.FileOutputStream(file));

		//init your data	
		String title = "Title XXXXXXXXX ";
		String date = java.text.DateFormat.getDateInstance().format(new java.util.Date());
		String columnNames = "support alg1 alg2........algn";
		int[] col1 = {2, 5, 34, 44};
		int[] col2 = {20, 31, 12, 29};
		String[] col3 = {"48s", "123s", "48s", "123s"};

		//start writing to the file
		printWriter.println(title );
		printWriter.println(date + "\r\n ");
		printWriter.println(columnNames);		
		for (int i = 0; i < col1.length	; i++)
		{
			StringBuffer row = new StringBuffer();
			row.append(col1[i]);
			row.append(" ");
			row.append(col2[i]);
			row.append(" ");
			row.append(col3[i]);
			
			printWriter.println(row.toString());
		}
		printWriter.close();
		
	}
	catch (Exception e)
	{
		System.out.println(e.getMessage());
	}
}
}
