How do I load variables from a file back into Scala? -


i have variables in scala have values written external file in format:

1 2 0 0.5 0.62 

this code puts them in file called "myvars.txt":

  val pw = new java.io.printwriter("myvars.txt")   pw.println(begingamecounter)   pw.println(trianglecount)   pw.println(trianglescore)   pw.println(lives)   pw.println(curplayer.getx)   pw.println(curplayer.gety)   pw.close 

how load these variables scala , replace old variables these new variables (for example old variable begingamecounter 0, when load file, want become 1)?

thank you.

you try this:

  val values = source.fromfile(pathtofile).getlines.tolist   begingamecounter = values(0)   trianglecount = values(1)   trianglescore = values(2)   lives = values(3)   currplayer.setx(values(4))   currplayer.sety(values(5)) 

this of course assumes variable on line consistent.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -