Link to home
Create AccountLog in
Avatar of tom1234
tom1234Flag for Korea, Republic of

asked on

How can I import files using *.java

I want make a 'arrayList<File>'

so like this , new File("some/*.java");
using asterisk, all of java file in some folder are to be set into arrayList.

how can I do this?
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
>>".*\.java"

change it to with escape

 ".*\\.java"
Avatar of Valeri
http://www.exampledepot.com/egs/java.io/GetFiles.html
just replace
return !name.startsWith(".");
with
return name.endsWith(".java");
ops, sorry, it's almost the same solution like ksivanant's one!
you can see also this:
http://www.exampledepot.com/egs/java.io/TraverseTree.html
>>>>
>>".*\.java"

change it to with escape

 ".*\\.java"
>>>>

Globs won't work - they're a shell thing. You need to traverse per the examples
>> return name.matches( ".*\.java" ) ;

The below is more efficient and has exactly the same effect
return name.endsWith( ".java" ) ;

Open in new window