Guest User

Untitled

a guest
Jan 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.84 KB | None | 0 0
  1. package com.builtin
  2.  
  3. import java.io.File
  4.  
  5. /**
  6.  * User: mbarisa
  7.  * Date: 10/8/11
  8.  */
  9.  
  10. class Conditions {
  11.   //def ifconfition() {
  12.   //  var filename = "default.txt"
  13.   //  if (!args.isEmpty)
  14.   //    filename = args(0)
  15.   //}
  16.   def dowhile() {
  17.     var line = ""
  18.     do {
  19.       line = readLine()
  20.       println("Read " + line)
  21.     } while (line != "")
  22.   }
  23.  
  24.   def fileLines(file: File) =
  25.     scala.io.Source.fromFile(file).getLines().toList
  26.  
  27.   def grep(pattern: String) {
  28.     val filesHere = (new File("/home/mbarisa")).listFiles
  29.     for (file <- filesHere
  30.          if file.getName.endsWith(".scala");
  31.          line <- fileLines(file)
  32.          if line.trim.matches(pattern)
  33.     )println(file + ": " + line.trim)
  34.    }
  35. }
  36.  
  37. object Conditions extends App {
  38.   //new Conditions().dowhile()
  39.   println(new Conditions().grep(".*object.*"))
  40.  
  41. }
Add Comment
Please, Sign In to add comment