Actually I wanna use the contents of the file to trigger an alarm.
Asked
Active
Viewed 2,999 times
2 Answers
1
try this snippet!
try {
InputStream inputStream = openFileInput("myfile.txt");
if (inputStream != null) {
InputStreamReader streamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(streamReader);
String l;
while (( l = bufferedReader.readLine()) != null) {
// do what you want with the line
}
}
inputStream.close(); //close the file
} catch (java.io.FileNotFoundException e) {
//file doesnt exist
}
dont forget the imports!
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;

Rejinderi
- 11,694
- 2
- 31
- 40
-
1what var is "in" ? is it a simply defined boolean?! – Alex Cio Jul 01 '12 at 20:09
0
Using java.io.BufferedReader
, you can read a line at a time with the readLine()
function. As you read each line, add it to an ArrayList<String>
. Finally, there are methods in ArrayList
that will help you copy the data out to an array, if an ArrayList
doesn't suit your purpose.
As to reading an xls, file, see this post.