I got a little problem.
I got a map (on android phone) called “Save”, in that folder I got several .txt files.
I know how to enter the folder, and I can read 1 txt file (hardcoded) but I want it to be dynamic.
I want somehting like this:
public void onClick(View v) {
File root = Environment.getExternalStorageDirectory();
save = root.toString()+"/Save/";
if (save.startsWith("3_test")){
System.out.println("FOUND!");
} else {
System.out.println("NOT FOUND!");
}
}
I got a txt file called 3_test.txt but he can’t find it this way, if I do it hardcoded it does find it.
The problem is that I don’t know how to “scan” all files in the folder Save and then put an “if” check over it.
Hope someone can help me with this.
I think your code won’t work in Java either: your
savevariable contais the path to the folder Save, under derootfolder.To achieve a filtered directory listing, you can try using the list() method on the File object for the Save folder, passing a custom
java.io.FilenameFilterimplementation, so it will scan the whole content of the target folder, and returning only the names of the files that match your constraint: