groovy - 如何修复除了 ''\n'';反正得到了

标签 groovy

我的代码中有以下行

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)
 } 

谢谢

最佳答案

只需关闭双引号

def genList = (args?.size() >=4)?args[3]: ""

关于groovy - 如何修复除了 ''\n'';反正得到了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17414356/

相关文章:

java - Gradle 动态填充 .properties-文件

java - Groovy gdk 命名空间冲突

java - 使用什么驱动程序与 Groovy/Gradle 一起连接到 Oracle 数据库

groovy - 在 Groovy 中访问闭包之外的变量

grails - 如何从GSP文件中的g:uploadForm获得结果(成功/失败)?

groovy - 当节点离线时 Jenkins 快速失败

unit-testing - Grails:测试域对象约束

grails - grails log4j事件记录器

scala - Mirah 比 JRuby、Groovy 和 Scala 提供了什么?

groovy - Grails脚手架默认日期