13
对于JAVA开发,我需要写一个字符串为“\ r \ t \ n <>”的文件,因为从Java我想写一个PHP文件。如果你不明白看看这个例子:在Java中有heredoc替代(heredoc as PHP)吗?
BufferedWriter buffW = new BufferedWriter(fileW);
buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>");
这是一个乱七八糟的代码,我想写一个干净如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;
?>
编写一个永远不会改变的PHP类的实用性只有一件事?您是否有更深入的示例将代码动态地放入PHP中?例如,如果我想为该文件添加一个函数 - 如果将该逻辑或方法分解为一个方法,那么与将长字符串放入Java相比,它将更容易且更具可读性。 – Makoto 2013-03-03 19:23:16
有些时候我很想拥有这个功能。大多数情况下,当我进行测试时,宁愿不处理文件I/O来测试简单的解析器。 – 2013-03-03 20:11:49
多行的[Java多行字符串](http://stackoverflow.com/questions/878573/java-multiline-string)的可能的重复,http://stackoverflow.com/questions/3034186/in-java-is-有一个方法来写一个字符串文字无需逃避报价不转义报价 – 2015-03-20 16:34:26