1

Actually I wanna use the contents of the file to trigger an alarm.

Ankur Kumar
  • 11
  • 1
  • 2

2 Answers2

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
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.

Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521