使用java/groovy将文件中某行上的分号替换为哈希

使用java/groovy将文件中某行上的分号替换为哈希,java,groovy,Java,Groovy,我有一个包含以下内容的文件 PackId1;ChannelId1;SalesCode1;AccountNumber1 PackId2;ChannelId2;SalesCode2;AccountNumber2 PackId3;ChannelId3;SalesCode3;AccountNumber3 PackId4;ChannelId4;SalesCode4;AccountNumber4 . . . . . PackId10;ChannelId10;SalesCode10;AccountNumber

我有一个包含以下内容的文件

PackId1;ChannelId1;SalesCode1;AccountNumber1
PackId2;ChannelId2;SalesCode2;AccountNumber2
PackId3;ChannelId3;SalesCode3;AccountNumber3
PackId4;ChannelId4;SalesCode4;AccountNumber4
.
.
.
.
.
PackId10;ChannelId10;SalesCode10;AccountNumber10
我编写代码来读取上述文件的第一行。现在,在读取行之后,我想将所有分号(;)替换为散列(#)或其他一些特殊字符,以便下次不读取同一行

请帮助我使用java/groovy将字符串(;)替换为(#)

尝试了如下所示的
replaceFirst()
,但对我无效

   str = str.replaceFirst("\\\;" , "\\\\#")
什么不起作用

 'PackId1;ChannelId1;SalesCode1;AccountNumber1 PackId2;ChannelId2;SalesCode2;AccountNumber2'.replace(';','#')

这里不需要使用正则表达式,就像这样。改用:

str = str.replace(";" , "#")

我用replace()尝试了以下代码:-def myFile=new File(“C:/Users/Desktop/Cont.txt”)def fileText=myFile.text str=fileText.split(“\n”)str=str.replace(“;”,“#”))它抛出错误“groovy.lang.MissingMethodException:没有方法签名:[Ljava.lang.String;。replace()适用于参数类型:(java.lang.String,java.lang.String)值:[;,#]可能的解决方案:第4行出现reverse()错误或者,在使用groovy读取文件后,是否有任何方法可以删除文件的第一行?最初,文件内容:PackId1;ChannelId1;salecode1;AccountNumber1 PackId2;ChannelId2;salecode2;AccountNumber2 PackId3;ChannelId3;AccountNumber3…..读取第一行文件内容后,文件内容应为PackId2;ChannelId2;salecode2;AccountNumber2 PackId3;ChannelId3;SalesCode3;AccountNumber3…..新文件(“C:/Users/Desktop/Cont.txt”)。使用reader{reader->而(reader.readLine()!=null){str1=reader.readLine()以上代码读取文件的第一行