在groovy文本文件的特定行开始循环 [英] Start loop at specific line of text file in groovy
问题描述
我正在使用groovy,并且正在尝试在特定行中更改文本文件,而无需循环遍历所有以前的行。有没有办法来表明你想要改变的文本文件的行?
例如
<文本文件是:
1
2
3
4
5
6
我想说
第(3)行= p
和让它将文本文件更改为:
1
2
p
4
5
6
我不想要循环遍历行来改变它的值,也就是我不想使用.eachline {line - > ...}方法。
先谢谢了,我真的很感激它!
我不认为你可以跳过这样的行和遍历。您可以使用随机访问文件 in java,但不是行,你应该指定字节数。
I am using groovy and I am trying to have a text file be altered at specific line, without looping through all of the previous lines. Is there a way to state the line of a text file that you want to wish to alter?
For instance
Text file is:
1
2
3
4
5
6
I would like to say
Line(3) = p
and have it change the text file to:
1
2
p
4
5
6
I DO NOT want to have to do a loop to iterate through the lines to change the value, aka I do not want to use a .eachline {line ->...} method.
Thank you in advance, I really appreciate it!
I dont think you can skip lines and traverse like this. You could do the skip by using the Random Access File in java, but instead of lines you should be specifying the number of bytes.
这篇关于在groovy文本文件的特定行开始循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!