import java.util.*;
import java.io.*;
public final class FileListing2
{
public static void main(String... aArgs) throws FileNotFoundException
{
File startingDirectory= new File(aArgs[0]);
List<File> files = FileListing.getFileListing(startingDirectory);
for(File file : files )
{
System.out.println(file);
}
}
static public List<File> getFileListing(File aStartingDir) throws FileNotFoundException
{
validateDirectory(aStartingDir);
List<File> result = getFileListingNoSort(aStartingDir);
Collections.sort(result);
return result;
}
static private List<File> getFileListingNoSort(File aStartingDir) throws FileNotFoundException
{
List<File> result = new ArrayList<File>();
File[] filesAndDirs = aStartingDir.listFiles();
List<File> filesDirs = Arrays.asList(filesAndDirs);
for(File file : filesDirs)
{
result.add(file);
if ( ! file.isFile() )
{
List<File> deeperList = getFileListingNoSort(file);
result.addAll(deeperList);
}
return result;
}
}
static private void validateDirectory (File aDirectory) throws FileNotFoundException
{
if (aDirectory == null)
{
throw new IllegalArgumentException("Directory should not be null.");
}
if (!aDirectory.exists())
{
throw new FileNotFoundException("Directory does not exist: " + aDirectory);
}
if (!aDirectory.isDirectory())
{
throw new IllegalArgumentException("Is not a directory: " + aDirectory);
}
if (!aDirectory.canRead())
{
throw new IllegalArgumentException("Directory cannot be read: " + aDirectory);
}
}
}
I copied this code from this site and am trying to adapt it to our environment. Sorry, I cannot get $%! @ # * ($ Thing for compilation. I keep getting an error with the main method: error: re-modifier.
public static void main(String... aArgs) throws FileNotFoundException is a string marked for error.
I do not see any duplicate modifiers here. All my braces and parens seem to be in the right places, and I'm completely at a dead end.
varargs... , ~ ~ ? Java, . , , String... String[]. , , String... .
- -, ? ,
spring brainteaser....