-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.java
More file actions
executable file
·67 lines (63 loc) · 1.41 KB
/
FileReader.java
File metadata and controls
executable file
·67 lines (63 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
64
65
66
67
package edu.wpi.first.wpilibj.templates;
import com.sun.squawk.microedition.io.FileConnection;
import com.sun.squawk.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import javax.microedition.io.Connector;
/**
* Reads the contents of a text file into a vector
*/
public class FileReader
{
/**
* Reads the contents of the file into a vector with each line placed into
* its own element
*
* @param filename The name of the file to read data from
* @return A vector with each element corresponding to a line in the text
* file
*/
public static Vector getFileContents(String filename)
{
String path = "file:///" + filename;
FileConnection file = null;
BufferedReader reader = null;
Vector contents = null;
try
{
file = (FileConnection) Connector.open(path, Connector.READ);
reader = new BufferedReader(
new InputStreamReader(file.openInputStream()));
contents = new Vector();
String line = "";
while((line = reader.readLine()) != null)
{
contents.addElement(line);
}
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if(reader != null)
{
reader.close();
}
if(file != null)
{
file.close();
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
return contents;
}
}