java判断文件是否是Parquet格式文件

Maven依赖配置


org.apache.parquet
parquet-hadoop
1.12.0



org.apache.hadoop
hadoop-common
2.7.1

判断方法 

 


import org.apache.hadoop.fs.Path;
import org.apache.parquet.hadoop.ParquetFileReader;
import org.apache.parquet.hadoop.metadata.ParquetMetadata;
import org.apache.hadoop.conf.Configuration;
public class ParquetFileChecker {
public static boolean isParquetFile(String filePath) {
try {
Configuration conf = new Configuration();
Path file = new Path(filePath);
ParquetMetadata parquetMetadata = ParquetFileReader.readFooter(conf, file);
return true;
} catch (Exception e) {
// An exception occurred while reading the file footer, so it's not a Parquet file
return false;
}
}
}

你可能感兴趣的:(java,数学建模,开发语言)