在Java中我该怎么做这里的文档?像 BASH 或 PHP 一样,我们可以

发布于 2024-12-13 14:18:49 字数 235 浏览 1 评论 0原文

我该如何使用Java。这里的文档像字符串吗?示例:

String java = << \EOF
#This file is written via Java
#You are watching JavaHereDoc
; comments ;
value=abc
etc etc

EOF;

System.out.println(java);显示与上面完全相同。我该怎么做?

How can i do with Java. Here doc like string? Exaple:

String java = << \EOF
#This file is written via Java
#You are watching JavaHereDoc
; comments ;
value=abc
etc etc

EOF;

System.out.println(java); shows exactly like above. How can i do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人迟暮 2024-12-20 14:18:49

不幸的是,Java(从 7 开始)不支持 HERE 文档(也称为多行字符串)。

如果您尝试完成模板化,有几个选项:

这些与 Perl 或 PHP 中的 HERE 文档并不完全相同,因为描述模板的字符串并不直接在您的代码中;它通常位于一个单独的文件中。

有一个提案提出Stephen Colebourne 以及 通过 Project Coin 提出的提案,但都没有进入 Java 7,这有点令人失望。 Groovy 和 Scala 等也在 JVM 上运行的语言确实支持多行字符串。

Java (as of 7) doesn't support HERE docs (also known as multiline strings) unfortunately.

If you're trying to accomplish templating, there are a few options:

These aren't exactly similar to HERE docs in Perl or PHP since the string that describes the template isn't directly in your code; it's usually in a separate file.

There was a proposal put forward by Stephen Colebourne as well as a proposal via Project Coin, neither of which made it into Java 7, which was a little disappointing. Languages like Groovy and Scala, which also run on the JVM do support multiline strings.

孤凫 2024-12-20 14:18:49

同时,如果您发现它很有用,这里有一个基本的 swing 应用程序,我用它来对嵌入到类中的 SQL 执行此操作。我发现自己一遍又一遍地使用它,为什么不分享它呢?

https://github.com/danielbchapman/Swing-String-Escaping-Utility

(一个小注释,它丢弃了代码,因为我在一周内将其组合在一起,我需要快速格式化查询,我可能会在某个时候清理它)

In the meantime if you find it useful here's a basic swing application I use to do this for SQL that's embedded into the classes. I find myself using it over and over again so why not share it?

https://github.com/danielbchapman/Swing-String-Escaping-Utility

(a small note, its throw away code since I put it together in a week where I needed to rapidly format queries, I might clean it up at some point)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文