-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
77 lines (62 loc) · 1.67 KB
/
ReadFile.java
File metadata and controls
77 lines (62 loc) · 1.67 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
68
69
70
71
72
73
74
75
76
77
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadFile
{
private String path;
public ReadFile(String file_path)
{
path = file_path;
}
public String[] OpenFile() throws IOException
{
FileReader fr = new FileReader(path);
BufferedReader textReader = new BufferedReader(fr);
int numberOfLines = readLines();
String[] textData = new String[numberOfLines];
int i;
for ( i = 0; i < numberOfLines; i++ )
textData[i] = textReader.readLine();
textReader.close();
return textData;
}
public int[] OpenTwoLine() throws IOException
{
FileReader fr = new FileReader(path);
BufferedReader textReader = new BufferedReader(fr);
int _a_size = Integer.parseInt(textReader.readLine());
int[] _a = new int[_a_size];
int _a_item;
String next = textReader.readLine();
String[] next_split = next.split(" ");
for ( int _a_i = 0; _a_i < _a_size; _a_i++ )
{
_a_item = Integer.parseInt(next_split[_a_i]);
_a[_a_i] = _a_item;
}
return _a;
}
public int[] OpenInt() throws IOException
{
FileReader fr = new FileReader(path);
BufferedReader textReader = new BufferedReader(fr);
int numberOfLines = readLines();
int[] textData = new int[numberOfLines];
int i;
for ( i = 0; i < numberOfLines; i++ )
textData[i] = Integer.parseInt(textReader.readLine());
textReader.close();
return textData;
}
public int readLines() throws IOException
{
FileReader fr = new FileReader(path);
BufferedReader textReader = new BufferedReader(fr);
String aLine;
int numberOfLines = 0;
while ( (aLine = textReader.readLine()) != null )
numberOfLines++;
textReader.close();
return numberOfLines;
}
}