Reputation: 107
I am trying to create multiple files. For example, t1.txt
, t2.txt
, etc.
I was thinking of something like code below, but it doesn't work:
val nbFiles = 15
for(n <- 1 to nbFiles) {
val writer = new PrintWriter(new File("t$n.txt"))
writer.write("Hello Scala")
writer.close()
}
I need a for
loop for making some process on each file.
Upvotes: 0
Views: 236
Reputation: 37928
You need to interpolate the string by preceding it with an s
:
val writer = new PrintWriter(new File(s"t$n.txt"))
^
Upvotes: 2