Reading file content randomly
in
Programming Questions
•
1 year ago
I intend to present Questions to my Users from a text file rather than an array.
Im facing Two problems:
1. How do i randomly Read separate lines from the file and
2. i would also love to put comment in the files, but i would not want to read the commented lines,( they are just there to help the user), assuming he intends to add more Questions to the game.
or is there a better Option apart from these two.
thank You
Code i have so far for reading file's content:
- File file = new File("data\questions.txt");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try{
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
...
}
1