尝试使用.dat
文件进行ip查找。文件位于Scala代码的Databricks文件存储中:
def getCountryCode(ip: String) {
val filePath = "FileStore/maxmind/GeoIPCountry.dat"
val ipLookups = new IpLookups(geoFile = Option(new File(filePath)),
ispFile = None, orgFile = None, domainFile = None, memCache = false, lruCache = 0)
val location = ipLookups.performLookups(ip)._1.head
println(location.countryCode)
}
我得到一个例外:
java.io.FileNotFoundException: FileStore/maxmind/GeoIPCountry.dat (No such file or directory)
方法适用于具有相对/绝对路径的本地环境
答案 0 :(得分:2)
使用FUSE安装文件系统上文件的完全限定路径:
val filePath = "/dbfs/FileStore/maxmind/GeoIPCountry.dat"