import java.io.File; import java.io.FileWriter; import java.io.IOException; /** * An example of how to write a 2-d array to a text file. * * @author Dave Slemon * @version v100 */ public class TestProgram { public static void main(String[] args) { String filename = "myfile.txt"; String[ ][ ] grid = { {"Jim", "Smith", "14", "freshman"}, {"Bob", "Jones", "18", "senior"}, {"Sue", "Reyes", "15", "sophmore"} }; try { //t FileWriter out = new FileWriter(filename); int numRows = grid.length; int numCols = grid[0].length; for(int r=0; r< numRows; r++) { for(int c=0; c< numCols; c++) { out.write(grid[r][c]); if (c != numCols-1) out.write("\t"); } out.write("\n"); } out.close(); System.out.println(filename + " successfully written."); } //t catch (IOException e) { //c System.err.println("Error: An error occurred while writing file: "+ filename); } //c } }