I have 1 input file with n lines. How can I create n output files from n lines?
I just know
for (line <- Source.fromFile(filePath).getLines) {
println(line)
}
I have 1 input file with n lines. How can I create n output files from n lines?
I just know
for (line <- Source.fromFile(filePath).getLines) {
println(line)
}
If the question is to know how to write the file, this can be done in two approaches.
1) By using PrintWriter
val writersample = new PrintWriter(new File("sample.txt" ))
writersample.write("put the content you want write")
//you can write as many lines as you want
writersample.close
2) By using FileWriter
val file = new File("sample.txt")
val bufferw = new BufferedWriter(new FileWriter(file))
bufferw.write("whatever you want to write here")
bufferw.close()
If you are looking to write n different files, probably you need to repeat the code by overriding the filename eachtime in a loop.
differences between both approaches can be read @ https://coderanch.com/t/418148/certification/Information-PrintWriter-FileWriter
Please let me know if you are looking for different answer than this.