package demo
import org.apache.commons.codec.digest.DigestUtils
/**
* Created by Administrator on 2015/12/18.
*/
/**
类名 - 对于所有的类名的第一个字母要大写。
方法名称 - 所有的方法名称的第一个字母用小写。
*/
object TestMain {
class Student{
var username="";
var age=0;
override def toString():String={
return username+age;
}
}
//Unit为没有返回值
def fuck(a:Int): Int =
{
println("a="+a)
return a;
}
//String为返回值
def sayHello(line:String): String ={
println("sayHello "+line)
return line;
}
def main(args: Array[String]) {
println("xxx");
val xx=fuck(12345)
println(xx)
val md5=DigestUtils.md5Hex("1024");
println(md5)
println(sayHello("dddd"))
val xxx=new Student;
xxx.age=1024;
xxx.username="fuck";
print(xxx.toString())
}
}
package demo
import java.io.{File, PrintWriter}
import scala.collection.immutable.SortedMap
import scala.io.Source
import scala.reflect.io.Path
/**
* Created by Administrator on 2015/12/18.
*/
object FileUtil {
val fnm = "d:/test.txt"
def writeFileDemo(p: Iterator[Path]) {
import java.io._
val writer = new PrintWriter(new File(fnm), "UTF-8")
var i = 0
p.foreach { f =>
i += 1
writer.write(i + "," + f + "\n")
}
writer.close
}
//无参函数
def readFileDemo = {
var sm = SortedMap[String, Int]()
val s = Source.fromFile(fnm, "UTF-8").getLines.foreach { s =>
val ss = s.split(",")
sm += ss(1) -> ss(0).toInt
}
//返回
sm
}
def main(args: Array[String]) {
var lstFile = {
val path = "D:\\data"
Path(path).walkFilter(p => p.isDirectory || ".*.txt".r.findFirstIn(p.name).isDefined)
}
writeFileDemo(lstFile)
readFileDemo.foreach(f => println(f))
//写入文件
val writer = new PrintWriter(new File("test.txt"))
writer.write("Hello Scala \n")
writer.close()
//读取文件
Source.fromFile("test.txt").foreach {
print
}
print("Please enter your input : ")
val line = Console.readLine //c#写法
println("Thanks, you just typed: " + line)
}
}