我有一个像下面的文件夹结构:
- main
-- java
-- resources
-- scalaresources
--- commandFiles
Run Code Online (Sandbox Code Playgroud)
在那个文件夹中,我有我必须阅读的文件.这是代码:
def readData(runtype: String, snmphost: String, comstring: String, specificType: String): Unit = {
val realOrInvFile = "/commandFiles/snmpcmds." +runtype.trim // these files are under commandFiles folder, which I have to read.
try {
if (specificType.equalsIgnoreCase("Cisco")) {
val specificDeviceFile: String = "/commandFiles/snmpcmds."+runtype.trim+ ".cisco"
val realOrInvCmdsList = scala.io.Source.fromFile(realOrInvFile).getLines().toList.filterNot(line => line.startsWith("#")).map{
//some code
}
val specificCmdsList = scala.io.Source.fromFile(specificDeviceFile).getLines().toList.filterNot(line => line.startsWith("#")).map{
//some code
}
}
} catch {
case e: Exception => e.printStackTrace
} …Run Code Online (Sandbox Code Playgroud) 如何检查所有列表元素是否为负数 - 如果任何单个值为正值则返回false 其他值true?
scala> val checkNegative = Map(
| "A" -> List(-1205678557, -1206583677, -1208669605, -1205679913),
| "B" -> List(-396902501, -397202715, -396902501, -396902501, -396902501),
| "C" -> List(-397502289, -397502289, -397502289, -397502289, -397502289),
| "D" -> List(-33902725, -33902725, -412803077, -33902725),
| "E" -> List(-458008664, -30433317),
| "F" -> List(300244, 300244, 300244, -396901292, 300244)
| )
checkNegative: scala.collection.immutable.Map[String,List[Int]] = Map(E -> List(-458008664, -30433317), F -> List(300244, 300244, 300244, -396901292, 300244), A -> List(-1205678557, -1206583677, -1208669605, -1205679913), B -> List(-396902501, …Run Code Online (Sandbox Code Playgroud)