我的代码中有以下行
def genList = (args[]?.size() >=4)?args[3]: "
当我运行我的整个代码时,我收到以下错误
除了''\ n''之外什么都没有期待;无论如何都得到了它:9,专栏:113这里我添加了整个代码,以便您可以看到我在做什么
def copyAndReplaceText(source, dest, targetText, replaceText){
dest.write(source.text.replaceAll(targetText, replaceText))
}
def dire = new File(args[0])
def genList = (args[]?.size() >=4)?args[3]: " // check here if argument 4 is provided, and generate output if so
def outputList = ""
dire.eachFile {
if (it.isFile()) {
println it.canonicalPath
// TODO 1: copy source file to *.bak file
copy = { File src,File dest->
def input = src.newDataInputStream()
def output = dest.newDataOutputStream()
output << input
input.close()
output.close()
}
//File srcFile = new File(args[0])
//File destFile = new File(args[1])
//File srcFile = new File('/geretd/resume.txt')
//File destFile = new File('/geretd/resumebak.txt')
File srcFile = it
File destFile = newFile(srcFile + '~')
copy(srcFile,destFile)
// search and replace to temporary file named xxxx~, old text with new text. TODO 2: modify copyAndReplaceText to take 4 parameters.
if( copyAndReplaceText(it, it+"~", args[1], args[2]) ) {
// TODO 3: remove old file (it)
it.delete()
// TODO 4: rename temporary file (it+"~") to (it)
// If file was modified and parameter 4 was provided, add modified file name (it) to list
if (genList != null) {
// add modified name to list
outputList += it + "\n\r"
}
}
}
}
// TODO 5: if outputList is not empty (""), generate to required file (args[3])
if (outputList != ""){
def outPut = new File(genList)
outPut.write(outputList)
}
谢谢
答案 0 :(得分:6)
请关闭双引号
def genList = (args?.size() >=4)?args[3]: ""
答案 1 :(得分:0)
为什么在这一行末尾有一个"
:def genList = (args[]?.size() >=4)?args[3]: "
?
你需要做到:def genList = (args[]?.size() >=4)?args[3]: ""
答案 2 :(得分:-2)
您需要在;
def outputList = ""
令牌
同时摆脱"
def genList = (args[]?.size() >=4)?args[3]: "