2014-05-05 42 views

回答

0
import org.apache.hadoop.fs.{FileSystem, FileUtil, Path} 
import scala.collection.mutable.Stack 


val fs = FileSystem.get(sc.hadoopConfiguration) 
var dirs = Stack[String]() 
val files = scala.collection.mutable.ListBuffer.empty[String] 
val fs = FileSystem.get(sc.hadoopConfiguration) 
dirs.push("/user/username/") 

while(!dirs.isEmpty){ 
    val status = fs.listStatus(new Path(dirs.pop())) 
    status.foreach(x=> if(x.isDirectory) dirs.push(x.getPath.toString) else 
    files+= x.getPath.toString) 
} 

files.foreach(println) 
相關問題