import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * Simple parser for the correlation data */ public class ParseFile { /** * Parse the file * @param _filename Filename */ public static void parse(String _filename) { try { Scanner input = new Scanner(new File(_filename)); // Ignore top comments String tag = "#"; while(tag.equals("#")) { input.nextLine(); tag = input.next(); } // Read columns and rows int cols = Integer.parseInt(tag); input.nextLine(); int rows = input.nextInt(); input.nextLine(); System.out.printf("%d rows and %d columns\n", rows, cols); // Read column headers for(int i = 0; i < cols; ++i) { String header = input.nextLine(); System.out.printf("Header %d: %s\n", i, header); } // Read data for(int i = 0; i < rows; ++i) { for(int j = 0; j < cols; ++j) { double d = input.nextDouble(); System.out.printf("%15.2f", d); } System.out.println(); } } catch(FileNotFoundException e) { System.out.println("File does not exist"); } } /** * Main parses the file specified as a command-line argument * @param _args Command-line arguments */ public static void main(String[] _args) { parse(_args[0]); } }