小编Use*_*er1的帖子

在java中读取和替换行

我试图逐行将file.txt读入java,然后当一行是"foo"时,我将它后面的行设置为"lineAfterFoo",然后将其输出给用户.

我的Java代码....

public void main(String[] args) throws IOException {

    try {
        FileReader someFile = new FileReader("file.txt");
        BufferedReader input = new BufferedReader(someFile);
        int i = 0;
        String[] line;
        line = new String[10];
        line[i] = input.readLine();

            while(line[i] != null) {

                line[i] = input.readLine();

                if (line[i] == "foo") {
                    i = i + 1;

                    line[i] = "lineAfterFoo";
                }

                i = i + 1;

            }

            for (int number = 1; number < i; number++) {
                System.out.println(line[number]);
            }

    } catch (FileNotFoundException e) {
        e.printStackTrace();

    } …
Run Code Online (Sandbox Code Playgroud)

java nosuchmethoderror

1
推荐指数
1
解决办法
754
查看次数

标签 统计

java ×1

nosuchmethoderror ×1