I'm using the following try/catch to try to parse a pipe-separated text file into an array ( each line is like this: spanishword|englishword|spanishword.mp3 ) for a flashcard app. Pretty simple, but I'm a complete noob. Here is what I cobbled together, which leads to the FileNotFoundException
.
The file is res/raw/first100mostcommon.txt. I like problem solving and am not really interested in being handed a solution, but a better hint than "file not found" would be appreciated.
I think String strFile = "R.raw.first100mostcommon";
is the right way to name it; is this right?
try
{
String strFile = "R.raw.first100mostcommon";
//create BufferedReader to read pipe-separated variable file
BufferedReader br = new BufferedReader( new FileReader(strFile));
String strLine = "";
StringTokenizer st = null;
int row = 0;
int col = 0;
//read pipe-separated variable file line by line
while( (strLine = br.readLine()) != null)
{
//break pipe-separated variable line using "|"
st = new StringTokenizer(strLine, "|");
while(st.hasMoreTokens())
{
//store pipe-separated variable values
stWords[row][col] = st.nextToken();
col++;
}
row++;
//reset token number
col = 0;
}
}
catch(Exception e)
{
text.setText("Exception while reading csv file: " + e);
}