-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadFileData.java
65 lines (57 loc) · 2.08 KB
/
ReadFileData.java
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
import java.io.*;
public class ReadFileData
{
public int getKeyIndex(String filepath){
int index = 0;
try{
File file=new File(filepath); //creates a new file instance
FileReader fr=new FileReader(file); //reads the file
BufferedReader br=new BufferedReader(fr); //creates a buffering character input stream
StringBuffer sb=new StringBuffer(); //constructs a string buffer with no characters
String line;
while((line=br.readLine())!=null)
{
index = Integer.parseInt(line);
}
fr.close();
} catch(IOException e){
e.printStackTrace();
}
return index;
}
public void updateKeyIndex(int current_index, String filename){
try{
String new_index = "" + (current_index + 1);
PrintWriter writer = new PrintWriter(filename);
writer.print(new_index);
// other operations
writer.close();
} catch(IOException e){
e.printStackTrace();
}
}
public int[] getData()
{
int data[] = new int[4]; // seed, mod, multiplier, increment
try
{
File file=new File("data.txt"); //creates a new file instance
FileReader fr=new FileReader(file); //reads the file
BufferedReader br=new BufferedReader(fr); //creates a buffering character input stream
StringBuffer sb=new StringBuffer(); //constructs a string buffer with no characters
String line;
int i = 0;
while((line=br.readLine())!=null)
{
data[i] = Integer.parseInt(line);
i++;
}
fr.close(); //closes the stream and release the resources
}
catch(IOException e)
{
e.printStackTrace();
}
return data;
}
}