Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:为什么不是';我的文件写不好吗?_Java_File_Io - Fatal编程技术网

Java:为什么不是';我的文件写不好吗?

Java:为什么不是';我的文件写不好吗?,java,file,io,Java,File,Io,我试图从我的Java程序中编写一个文件,但什么也没发生。我没有收到任何异常或错误,只是默默地失败了 try { File outputFile = new File(args[args.length - 1]); outputFile.delete(); outputFile.createNewFile(); PrintStream output = new PrintStream(n

我试图从我的Java程序中编写一个文件,但什么也没发生。我没有收到任何异常或错误,只是默默地失败了

        try {
            File outputFile = new File(args[args.length - 1]);
            outputFile.delete();
            outputFile.createNewFile();
            PrintStream output = new PrintStream(new FileOutputStream(outputFile));
            TreePrinter.printNewickFormat(tree, output);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
以下是
TreePrinter
功能:

public static void printNewickFormat(PhylogenyTree node, PrintStream stream) {
    if (node.getChildren().size() > 0) {
        stream.print("(");
        int i = 1;
        for (PhylogenyTree pt : node.getChildren()) {
            printNewickFormat(pt, stream);
            if (i != node.getChildren().size()) {
                stream.print(",");
            }
            i++;
        }
        stream.print(")");
    }
    stream.format("[%s]%s", node.getAnimal().getLatinName(), node.getAnimal().getName());
}

我做错了什么?

关闭和/或刷新输出流:

TreePrinter.printNewickFormat(tree, output);
output.close(); // <-- this is the missing part
} catch (IOException e) {
TreePrinter.printNewickFormat(树,输出);

output.close();// 关闭和/或刷新输出流:

TreePrinter.printNewickFormat(tree, output);
output.close(); // <-- this is the missing part
} catch (IOException e) {
TreePrinter.printNewickFormat(树,输出);

output.close();// 刷新打印流。

刷新打印流。

在这种情况下,节点必须为空-不会向文件写入任何内容。您可以通过在关闭之前打印一些内容来测试是否是这种情况(或者您有其他问题),例如
output.println(“测试”)在这种情况下,节点必须为空-不会向文件写入任何内容。您可以通过在关闭之前打印一些内容来测试是否是这种情况(或者您有其他问题),例如
output.println(“测试”)该代码保证至少创建一个(可能为空)文件或引发一些异常。该代码保证至少创建一个(可能为空)文件或引发一些异常。