我有一个从大型json文件加载并从中获取模式的DataFrame。该模式基本上围绕着1000列。我希望将printSchema的相同输出保存在文件中,而不是控制台。
有什么想法吗?
有什么想法吗?
如果您是在本地环境下工作,您可以执行以下操作:
val filePath = "/path/to/file/schema_file"
new PrintWriter(filePath) { write(df.schema.treeString); close }
如果您使用的是HDFS,则需要提供一个URI。
/**
* Prints the schema to the console in a nice tree format.
* @group basic
* @since 1.3.0
*/
// scalastyle:off println
def printSchema(): Unit = println(schema.treeString)
// scalastyle:on println
val out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);