新扫描程序(文件)中的FileNotFoundException失败:
// Option 1: peopleDF.write.parquet("people.parquet")
//Option 2:
peopleDF.write.format("parquet").mode(SaveMode.Append).saveAsTable("people.parquet")
// Read in the parquet file created above
val parquetFile = spark.read.parquet("people.parquet")
//Parquet files can also be registered as tables and then used in SQL statements.
parquetFile.registerTempTable("parquetFile")
val teenagers = sqlContext.sql("SELECT * FROM people.parquet")
但这样运行正常,没有任何异常(同一个包中的类):
public class Ex1 {
public static void main(String[] args) {
// boot.txt -is in its own "resource" source folder in Eclipse
String fileName = Ex1.class.getResource("/boot.txt").toExternalForm();
File file = new File(fileName); // File (String pathname) ctor
Scanner sc;
try {
sc = new Scanner(file); // FileNotFoundException here
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
有什么问题
public class Ex2 {
public static void main(String[] args) {
URL fileURL = Ex2.class.getResource("/boot.txt");
Scanner sc;
try {
File file = new File(fileURL.toURI());
sc = new Scanner(file); // fine!
} catch (FileNotFoundException | URISyntaxException e) {
e.printStackTrace();
}
}
This导致Scanner ctors之间的“奇怪”差异,但没有回答这个问题......