0

the title is pretty self explanatory. I need to be able to read the file names of all the .txt files in a specific folder and add them to an array. can this be done with the scanner class?

3 Answers3

1

No. A Scanner reads data from files, streams, Strings or anything that implements the Readable interface. This has nothing to do with accessing the filesystem structure. You need:

http://docs.oracle.com/javase/tutorial/essential/io/dirs.html

Brian Roach
  • 76,169
  • 12
  • 136
  • 161
0

no, you can't use scanner for that, scanner only helps you parse a string or a file's content, for what you want to achieve, have a look at this

Also, have a look at Scanner's documentation

Community
  • 1
  • 1
0

No, the Scanner class is only used for reading data in file, not read files in a folder. To read the data from a file you have specify the name file in constructor of Scanner while creating the object.

Jimshad Abdulla
  • 167
  • 2
  • 8