-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMnistData.java
More file actions
63 lines (54 loc) · 1.41 KB
/
MnistData.java
File metadata and controls
63 lines (54 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.ArrayList;
public class MnistData{
//holds each line in the csv as an element.
private ArrayList<String> data = new ArrayList<String>();
public MnistData(){
}
public MnistData(String filename){
storedata(filename);
}
/**
* reads in and stores data from file.
*
*@param String fileName : file to read from.
*/
private void storedata(String fileName){
// check to make sure file opens and is read correctly.
try{
//temporarily hold line data.
String line = null;
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
//stores data into ArrayList Data one line at a time.
while((line = bufferedReader.readLine()) != null){
this.data.add(line);
}
//close file
bufferedReader.close();
} catch(FileNotFoundException ex) {
System.out.println("File not found!");
} catch(IOException ex) {
ex.printStackTrace();
}
}
/**
* returns queried data given index.
*
*@param int index
*@return String : mnist line data.
*/
public String getDataByIndex(int index){
return data.get(index);
}
/**
* return size of data.
*/
public int dataSize(){
return this.data.size();
}
}