GeSHi (java):
package Tutorial
object ControlStructures {
val location = "c:\\"
val fileType = ".ini"
val files =
(new java.
io.
File(location
)).
listFiles
// We can add in for expression if statements, filtering
for (file <- files if file.getName.endsWith(fileType)) {
println(file.getName)
}
}
}
Created by GeSHI 1.0.7.20
with more filtering..
GeSHi (java):
object ControlStructures {
val location = "c:\\"
val files =
(new java.
io.
File(location
)).
listFiles
// We can add in for expression if statements, filtering
for (
file <- files
if file.isFile; // need to add semicolons because it's meant as a one line
if file.canRead;
if file.getName.endsWith(".sqm")
) println(file.getName)
}
}
Created by GeSHI 1.0.7.20
Searching in files, also this example uses nested looping
GeSHi (java):
object ControlStructures {
val location = "c:\\"
val fileType = ".txt"
val files =
(new java.
io.
File(location
)).
listFiles
def fileLines
(file: java.
io.
File) =
scala.io.Source.fromFile(file).getLines.toList
for (
file <- files
if file.getName.endsWith(fileType);
line <- fileLines(file)
if line.trim.matches(pattern)
) println(file.getName + "=> " + line.trim)
grep(".*Java.*")
}
}
Created by GeSHI 1.0.7.20