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

Marin Sagovac picture Marin Sagovac · Mar 3, 2013 · Viewed 12.8k times · Source

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:

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
$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;
?> 

Answer

user626607 picture user626607 · Mar 3, 2013

Is there a heredoc equivalent in Java?

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

Check this similar question.