2016-04-19 119 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 方法。

相關問題