I have a java class where it reads some data from a text file using a buffered reader and returns that data as a hash map:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
public class FrequencyLoader {
public FrequencyLoader() throws FileNotFoundException {
}
public HashMap<String, Double> loadUnigramFrequencies() throws FileNotFoundException, IOException {
HashMap<String, Double> unigramFrequencies = new HashMap<String, Double>();
String line;
String[] splittedLine;
BufferedReader bf = new BufferedReader(new FileReader("unigramFrequencies.txt"));
while ((line = bf.readLine()) != null) {
splittedLine = line.split("\\s");
unigramFrequencies.put(splittedLine[0].trim(), Double.parseDouble(splittedLine[1].trim()));
}
return unigramFrequencies;
}
}
I want to use that in my android application but when I create an instance of this class and try to execute the loadUnigramFrequencies() function in the android Activity class I am getting an error that the application has stopped unexpectedly. I am trying to run it on Samsung Galaxy S2. Should the file be placed somewhere in the android project rather than on the disk? if yes then where?