遍历输入文件的每一行,将第一个出现的空格,替换为tab分隔符。
import java.io.{File, PrintWriter}
import scala.io.Source
object codingPractice {
def main(args: Array[String]) :Unit = {
val fileName = args(0)
val writer = new PrintWriter(new File("./output.txt"))
for(line <- Source.fromFile(fileName).getLines()){
// println(line)
val newLine = line.replaceFirst(" ","\t")
writer.write(newLine)
writer.write("\n")
}
writer.close()
}
}