I have to find a file ard12333.txt but the number part is variable so I should check if the file contains the string "ard" and then extrapolate the number part. How to do that?
Asked
Active
Viewed 3,416 times
-5
-
I don't know how to start.. I know how to check if file exsists in directory but nothing more.. – user3832184 Oct 28 '14 at 08:43
-
try with reading file name into string and using string functions – HackerGK Oct 28 '14 at 08:43
-
Java Tutorial [Finding Files](http://docs.oracle.com/javase/tutorial/essential/io/find.html) – DavidPostill Oct 28 '14 at 08:54
2 Answers
0
Steps for your work :
1) Fetch the file name from directory.
2) Check whether it contains ard
or not.
3) If yes, then convert the rest of file name without extension to Integer or Long or whatever Number. If No, go to step 1 to check next file if any.
4) If value of variable and converted number matches, wooohhooo you are done. Break the loop and do whatever you want.

Vimal Bera
- 10,346
- 4
- 25
- 47
0
read all files in folder while checking name. file reading process is in this link. check this.
you can check file names start with String.startsWith()
method to find start letters in file name string.