I am trying to read a fixed width file and writting it as text file ,below is the code . Input file layout length of the fields(4,10,3,5,3,1,1,5,7)
094482018-07-10 022 14012 000 0 30000A 002290{
059412018-07-10 022 14013 000 0 30000A 002290{
015172018-07-10 046 17502 000 0 30000A 001699I
scala> val inputdata = scala.io.Source.fromFile("/C:/Users/rrrrrr/Desktop/datas
tage/inputdata.txt")
inputdata: scala.io.BufferedSource = non-empty iterator
scala> val lines = inputdata.getLines
lines: Iterator[String] = non-empty iterator
scala> val matched=lines.map(l=>(l.substring(0,5).trim(),l.substring(5,5).trim()
))
matched: Iterator[(String, String)] = non-empty iterator
scala> val outputdata= new File("/C:/Users/rkumar0/Desktop/folder/output_N4.txt"
)
outputdata: java.io.File = C:\Users\rrrrrrr\Desktop\folder\output_N4.txt
scala> val writer= new BufferedWriter(new FileWriter(outputdata))
writer: java.io.BufferedWriter = java.io.BufferedWriter@759c0c14
scala> matched.foreach{line =>
| writer.write(line)
| writer.newLine()
| }
<console>:19: error: overloaded method value write with alternatives:
(x$1: Int)Unit <and>
(x$1: String)Unit <and>
(x$1: Array[Char])Unit
cannot be applied to ((String, String))
writer.write(line)
^
scala>
and my output file created empty.