Java Reference
In-Depth Information
7 numberOfValues
8 value1
9 value2
10 ...
11 */
12 public class DataSetReader
13 {
14 /**
15 Reads a data set.
16 @param filename the name of the file holding the data
17 @return the data in the file
18 */
19 public double [] readFile(String filename)
20 throws IOException, BadDataException
21 {
22 FileReader reader = new Fi leReader(fil
ename);
23 try
24 {
25 Scanner in = new Scanner(reader);
26 readData(in);
27 }
28 finally
29 {
30 reader.close();
31 }
32 return data;
33 }
34
35 /**
36 Reads all data.
37 @param in the scanner that scans the data
38 */
39 private void readData(Scanner in) throws
BadDataException
40 {
41 if (!in.hasNextInt())
42 throw new BadDataException( ÐLength
expectedÑ );
43 int numberOfValues = in.nextInt();
44 data = new double [numberOfValues];
518
519
Search WWH ::




Custom Search