java如何将数字增加1?
我需要输入数字的文件
https://github.com/eggham0518/helpme/blob/master/yukim_720.sql
我把它从1放到84
我的一次尝试
public class main {
public static void main(String[] args) throws IOException {
String fileName = "C:/Users/kang/Downloads/yukim.txt";
List<String> newLines = new ArrayList<>();
for (String line : Files.readAllLines(Paths.get(fileName), StandardCharsets.ISO_8859_1)) {
if (line.contains("INSERT INTO yukim_720 VALUES ( '")) {
newLines.add(line.replace("INSERT INTO yukim_720 VALUES ( '", "INSERT INTO yukim_720 VALUES ( '"+ "'" +i++));
} else {
newLines.add(line);
}
}
Files.write(Paths.get(fileName), newLines, StandardCharsets.ISO_8859_1);
}
}
# 1 楼答案
你在正确的轨道上。只需声明并初始化一个行号计数器,就可以了。遵循以下步骤: