cactoos面向对象的 Java 库的集合
cactoos 是一个面向对象的 Java 原语的集合,是 Google Guava 和 Apache Commons 的替代品。
动机:JDK, Guava 和 Apache Commons 是程序化的而不是面向对象的。他们主要是通过静态方法来工作的。Cactoos 则是通过面向对象。
如何使用。库没有依赖性,在这里获得最新版本:
< dependency >
< groupId > org.cactoos </ groupId >
< artifactId > cactoos </ artifactId >
</ dependency >
Java版本要求:1.8+。
StackOverflow标签是cactoos。
输入输出
以UTF-8读取文本文件:
String text = new TextOf(
new File(“/ code/a.txt ”)
)。asString();
将文本写入文件:
new LengthOf(
new TeeInput(
“ Hello,world!”,
new File(“/ code/a.txt ”)
)
)。的intValue();
从classpath读取二进制文件:
byte [] data = new BytesOf(
new ResourceOf(“ foo / img.jpg ”)
)。asBytes();
评论
