湖南对外建设集团网站温州网站建设联系电话
web/
2025/10/7 23:27:31/
文章来源:
湖南对外建设集团网站,温州网站建设联系电话,网站建设与管理代码,哈尔滨建设工程交易中心网站q7goodies事例在Data Geekery #xff0c;我们喜欢Java。 而且#xff0c;由于我们真的很喜欢jOOQ的流畅的API和查询DSL #xff0c;我们对Java 8将为我们的生态系统带来什么感到非常兴奋。 我们已经写了一些关于Java 8好东西的博客 #xff0c;现在我们觉得是时候开始一个… q7goodies事例 在Data Geekery 我们喜欢Java。 而且由于我们真的很喜欢jOOQ的流畅的API和查询DSL 我们对Java 8将为我们的生态系统带来什么感到非常兴奋。 我们已经写了一些关于Java 8好东西的博客 现在我们觉得是时候开始一个新的博客系列了…… Java 8星期五 每个星期五我们都会向您展示一些不错的教程风格的Java 8新功能这些功能利用了lambda表达式扩展方法和其他出色的功能。 您可以在GitHub上找到源代码 。 Java 8 Goodie带有Lambdas的java.io 与文件系统进行交互在Java中有些痛苦。 CTMMC向我们展示了如何使用Java复制文件的示例 。 尽管仍然存在一些问题至少我们现在可以使用lambda和新的Streams API 遍历文件系统并列出文件 这是我们已推送到GitHub存储库的FileFilterGoodies示例 public class FileFilterGoodies {public static void main(String args[]) {listRecursive(new File(.));}/*** This method recursively lists all* .txt and .java files in a directory*/private static void listRecursive(File dir) {Arrays.stream(dir.listFiles((f, n) -!n.startsWith(.)(f.isDirectory()|| n.endsWith(.txt)|| n.endsWith(.java)))).forEach(unchecked((file) - {System.out.println(file.getCanonicalPath().substring(new File(.).getCanonicalPath().length()));if (file.isDirectory()) {listRecursive(file);}}));}/*** This utility simply wraps a functional* interface that throws a checked exception* into a Java 8 Consumer*/private static T ConsumerTunchecked(CheckedConsumerT consumer) {return t - {try {consumer.accept(t);}catch (Exception e) {throw new RuntimeException(e);}};}FunctionalInterfaceprivate interface CheckedConsumerT {void accept(T t) throws Exception;}
} 上面程序的输出是 \jOOQs Java 8 Goodies.iml
\LICENSE.txt
\out
\out\production
\out\production\jOOQs Java 8 Goodies
\out\production\jOOQs Java 8 Goodies\org
\out\production\jOOQs Java 8 Goodies\org\jooq
\out\production\jOOQs Java 8 Goodies\org\jooq\java8
\out\production\jOOQs Java 8 Goodies\org\jooq\java8\goodies
\out\production\jOOQs Java 8 Goodies\org\jooq\java8\goodies\io
\out\production\jOOQs Java 8 Goodies\org\jooq\java8\goodies\io\FileFilterGoodies$CheckedConsumer.class
\out\production\jOOQs Java 8 Goodies\org\jooq\java8\goodies\io\FileFilterGoodies.class
\README.txt
\src
\src\org
\src\org\jooq
\src\org\jooq\java8
\src\org\jooq\java8\goodies
\src\org\jooq\java8\goodies\io
\src\org\jooq\java8\goodies\io\FileFilterGoodies.java 现在这真的很棒不是吗 让我们分解上面的listRecursive()方法 // With this method, we wrap the File[] array
// into a new Java 8 Stream, which has awesome
// new methods.
Arrays.stream(// The Java 1.2 File.listFiles() method luckily
// accepts a FunctionalInterface, which can be
// instantiated using a lambda expression
// ...
// In this example, well just ignore the fact
// that listFiles can return nulldir.listFiles((f, n) -!n.startsWith(.)(f.isDirectory()|| n.endsWith(.txt)|| n.endsWith(.java))))// Each Stream (and also java.util.List) has this
// awesome forEach method, that accepts a Consumer.forEach(// Unfortunately, Java 8 Consumers dont allow
// throwing checked exceptions. So lets quickly
// wrap it (see details below) ...unchecked(// ... and pass another lambda expression to it,
// which prints the local path and recurses(file) - {System.out.println(file.getCanonicalPath().substring(new File(.).getCanonicalPath().length()));if (file.isDirectory()) {listRecursive(file);}}));下周会有更多好吃的东西 请继续关注下周当我们向您展示如何在jOOX中使用XML改进Java 8时 参考 Java 8 Friday Goodiesjava.io终于成功了 从我们的JCG合作伙伴 Lukas Eder在JAVASQL和JOOQ博客中获得。 翻译自: https://www.javacodegeeks.com/2014/01/java-8-friday-goodies-java-io-finally-rocks.htmlq7goodies事例
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/88744.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!