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
Is there heredoc alternative in Java (heredoc as PHP)?
提问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;
?>