public class database { String fileName; Scanner input; String[][] data; List useful_list; List records; ArrayList handles;
public database(String fileName) { this.fileName = fileName; }
public void openFile() { try { input = new Scanner(new File(fileName)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block return; } }
public void readRecords() { // Read all lines (records) from the file into an ArrayList records = new ArrayList(); try { while (input.hasNext()) records.add(input.nextLine());
public void parseFields() { String delimiter = ",\n";
// Create two-dimensional array to hold data (see Deitel, p 313-315) int rows = records.size(); // #rows for array = #lines in file data = new String[rows][]; // create the rows for the array int row = 0;
for (String record : records) { StringTokenizer tokens = new StringTokenizer(record, delimiter); int cols = tokens.countTokens(); data[row] = new String[cols]; // create columns for current row int col = 0; while (tokens.hasMoreTokens()) { data[row][col] = tokens.nextToken().trim();
col++;
}
row++;
}
}
public static void main(String[] args) { String filename = null; String[] values = new String[4]; String input = null;
BufferedReader reader = new BufferedReader(new InputStreamReader( System.in));