Normal
also listFiles kann null zurückgeben, daher dann auch die NPE.Passiert z.b. bei nem windows rechner wenn man in die eigenen dateien reinmöchte.laut API:EDIT:ne kleine if abfrage sollte da abhilfe schaffen:[code=Java] public static void main(String[] args) { List<File> list = getAllFiles( new File( "C:\\" )); for ( File f : list ) System.out.println( f.getAbsolutePath() ); } public static List<File> getAllFiles( File path ) { List<File> ret = new ArrayList<File>(); File[] files = path.listFiles(); if (files != null) { for ( File f : files ) { if ( f.isDirectory() ) { ret.addAll( getAllFiles( f ) ); } else { ret.add( f ); } } } return ret; }[/code]
also listFiles kann null zurückgeben, daher dann auch die NPE.
Passiert z.b. bei nem windows rechner wenn man in die eigenen dateien reinmöchte.
laut API:
EDIT:
ne kleine if abfrage sollte da abhilfe schaffen:
[code=Java] public static void main(String[] args) {
List<File> list = getAllFiles( new File( "C:\\" ));
for ( File f : list )
System.out.println( f.getAbsolutePath() );
}
public static List<File> getAllFiles( File path ) {
List<File> ret = new ArrayList<File>();
File[] files = path.listFiles();
if (files != null) {
for ( File f : files ) {
if ( f.isDirectory() ) {
ret.addAll( getAllFiles( f ) );
} else {
ret.add( f );
return ret;
}[/code]