在 Scala 中将文件内容拆分为 Array[String]

Split contents of file into Array[String] in Scala

我有一个包含多个查询的 SQL 文件。由于它是一个 SQL 文件,因此它包含用分号 (;) 分隔的查询。我想读取 SQL 文件并将查询作为 Scala 中的 Array[String]

例如,我有 queries.sql 文件,其中包含如下查询:

select * from table1;
select col1,col2,col3 from table1 where col1 = ''
col2 = '';
select count(*) from table;

我希望输出如下所示:

Array("select * from table1","select col1,col2,col3 from table1 where col1 = '' col2 =' '","select count(*) from table")

您可能想试试这个:

import scala.io.Source
val theArrayYouWant = Source.fromFile(<filename>).getLines.mkString.split(";")