java Java中是否有heredoc替代品(heredoc作为PHP)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15189679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:46:21  来源:igfitidea点击:

Is there heredoc alternative in Java (heredoc as PHP)?

javaphpreadfileheredoc

提问by Marin Sagovac

For JAVA development I need writing to a files with strings like "\r\t\n <>", because from Java I want writing a PHP file. If you can't understand look at this example:

对于 JAVA 开发,我需要写入带有诸如“\r\t\n <>”之类的字符串的文件,因为我想从 Java 中编写一个 PHP 文件。如果你不明白看这个例子:

BufferedWriter buffW = new BufferedWriter(fileW);
            buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>");

This is mess a code, I want to write a clean such as PHP can do, but can't find on Java alternative way as example:

这是一个乱码,我想写一个像PHP这样的干净代码可以做到,但是在Java上找不到替代方法,例如:

 <?php
$mystring = <<<EOT
    This is some PHP text.
    It is completely free
    I can use "double quotes"
    and 'single quotes',
    plus $variables too, which will
    be properly converted to their values,
    you can even type EOT, as long as it
    is not alone on a line, like this:
EOT;
?> 

采纳答案by Marin Sagovac

Is there a heredocequivalent in Java?

heredocJava中是否有等价物?

No, there is no direct heredocalternative in the Java programming language.

不,heredoc在 Java 编程语言中没有直接的替代方案。

Check this similar question.

检查这个类似的问题