I'm trying to keep a .txt file in my res\raw file in Android Studio and read/parse the file. I have a file "my_file.txt" in a folder called "raw" that I created in the "res" directory (that I didn't create).
Here's what I think my main issue is: When creating the File object (to use with the Scanner object), what path should I pass in for my text file?
Here's my code:
private void readFile(){
Scanner scanner = null;
try {
scanner = new Scanner(new File("\\res\\raw\\my_file.txt")); //I've also tried without the .txt extension
Log.v("readFile->try","Trying to read file.");
}catch(Exception e)
{
//Send error message.
}
if(scanner != null) {
while (scanner.hasNext()) {
String[] line = scanner.nextLine().split("\t");
//Process string here
}
}
}
0 comments:
Post a Comment