如何把数字增加一个?

我需要输入数字的文件


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);


    }

}


BIG阳
浏览 94回答 1
1回答

慕盖茨4494581

您走在正确的轨道上。只需声明并初始化行号的计数器,就可以开始了。请遵循以下命令:public class main {&nbsp; &nbsp; public static void main(String[] args) throws IOException {&nbsp; &nbsp; &nbsp; &nbsp; String fileName = "C:/Users/kang/Downloads/yukim.txt";&nbsp; &nbsp; &nbsp; &nbsp; List<String> newLines = new ArrayList<>();&nbsp; &nbsp; &nbsp; &nbsp; int i = 85; // <- you lack this one, start from 85 and not 0 since there are already lines that has value and the last one is 84&nbsp; &nbsp; &nbsp; &nbsp; for (String line : Files.readAllLines(Paths.get(fileName), StandardCharsets.ISO_8859_1)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (line.contains("INSERT INTO yukim_720 VALUES ( ''")) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newLines.add(line.replace("INSERT INTO yukim_720 VALUES ( '",&nbsp; &nbsp; "INSERT INTO yukim_720 VALUES ( '"+(i++))); // this line was edited&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newLines.add(line);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; Files.write(Paths.get(fileName), newLines, StandardCharsets.ISO_8859_1);&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java