导入文档和更改文档的字符串以及在新的.txt文档中输出新字符串时出现问题

时间:2016-01-07 15:30:55

标签: java string

然后它应该输出一个新的.txt文档,但是当它输出时,它会输出原始文档。我收到错误消息:

public static String Replace(String filename) {
    try {
        Scanner file = new Scanner(new File(filename));
        System.out.println(file);
        StringBuilder b = new StringBuilder();
        String s = "";
        while(file.hasNextLine()){

            s = file.nextLine();


            if (s.equals("X")) {
                s = "0";
                b.append(s).append(System.getProperty("line.separator"));
            } else {
                b.append(s).append(System.getProperty("line.separator"));
            }

        }
        try (PrintStream out = new PrintStream(new FileOutputStream("test1,1.txt"))) {
            out.print(b);
            out.close();
        } catch (IOException e) {

        }

    } catch (Exception e) {
        System.out.println("Problem reading file.");
    }
    return "ok";
}

如果我注释掉了" ok",否则它会创建一个与原始文档具有相同详细信息的新文档。

可能是什么原因?

Column B     Column C
Sam          Ziva
Jen          Tiva
Leo          Miva

0 个答案:

没有答案