Advertisement
SergOmarov

Untitled

Sep 5th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.40 KB | None | 0 0
  1. def specifedLoadFromFile[T](filePath:File)(implicit tag:ClassTag[T]): T = {
  2.     try {
  3.       val oos = new ObjectInputStream(new FileInputStream(filePath))
  4.       val data = oos.readObject.asInstanceOf[T]
  5.       oos.close()
  6.       data
  7.     } catch {
  8.       case e: Exception => new T()//Типо ,если не могли прочитать из файла, то создадим пустую
  9.     }
  10.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement