|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
Search Directory or Folder for files?
Maybe I'm just missing it, or maybe it can't be done. Is there a way to search through a folder for a file and display it if it exists?
I'm putting together a departmental intranet site and would like to display .pdf files. Can I search a folder directly for a file or do I need a database? Thanks, Walt |
|
#2
|
|||
|
|||
|
A directory is considered a File in java, so look into the 'FileReader' class. Though I have not tried it, you should be able to open a directory and read what files are available I would think.
|
|
#3
|
|||
|
|||
|
There are several classes in java.io for searching and manipulating directories. Here's the simplest approach.
import java.io.File; class ListFiles { File directoryOfPdfs = new File("/mypdfs"); // Directory is just a list of files if(directoryOfPdfs.isDirectory() { // check to make sure it is a directory String filenames[] = directoryOfPdfs.list(); make array of filenames. } } That gives you an array of all the filenames in a given directory. Loop through and process however you want. There is also a FilenameFilter interface if you want to create filters that can be handed to the list() method. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Search Directory or Folder for files? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|