forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.java
32 lines (28 loc) · 1001 Bytes
/
reader.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
import java.io.*;
import java.util.Scanner;
public class reader {
static int currentQues = 0;
static FileInputStream fis1 = null, fis2 = null;
static Scanner sc1 = null, sc2 = null;
//It reads the questions from Question.txt and returns the one question and its option
static String[] readQues() throws FileNotFoundException {
if (currentQues == 0) {
fis1 = new FileInputStream("Questions.txt");
sc1 = new Scanner(fis1);
}
String[] list = new String[2];
list[0] = sc1.nextLine();
list[1] = sc1.nextLine();
currentQues++;
return list;
}
//It reads the answer of selected question from AnswerKey.txt and returns its correct option
static String readAns() throws FileNotFoundException {
if (currentQues == 1) {
fis2 = new FileInputStream("AnswerKey.txt");
sc2 = new Scanner(fis2);
}
String ans = sc2.nextLine();
return ans;
}
}