2016-04-19 117 views
0

我想使用Apache commons CSV解析器解析CSV文件,但groovy在传递分隔符';'时抛出异常。作为字符,因为groovy传递一个java.lang.Character,并且该方法需要一个原始字符。 我在我的单元测试中使用groovy,java 7.没有方法的签名:CSVFormat.withDelimiter()适用于参数类型:[;]?

任何机构都知道如何解决这个问题?

//Create the CSVFormat object 
    CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(';'); 

    //initialize the CSVParser object 
    CSVParser parser = new CSVParser(new FileReader(filePath), format); 


groovy.lang.MissingMethodException: No signature of method: org.apache.commons.csv.CSVFormat.withDelimiter() is applicable for argument types: (java.lang.String) values: [,] 
Possible solutions: withDelimiter(char), getDelimiter() 
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55) 
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46) 
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) 
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 
at test.ca.azb.j2ee.obb3.TestPersistence.testLoadHyrCsvToHyrTable(TestPersistence.groovy:226) 

回答

1

事实上,Groovy的是传递一个String

groovy.lang.MissingMethodException:法无签名:org.apache.commonsormat.withDelimiter()是适用于参数类型:(java.lang.String中)...

​​3210是一个字符串,但您可以turn it into a character

CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(';' as char) 

';' as char实际上会产生java.lang.Character但Groovy的将解开它为您生产所要求的char 方法。

相关问题