cactoos面向?qū)ο蟮?Java 庫(kù)的集合
cactoos 是一個(gè)面向?qū)ο蟮?Java 原語(yǔ)的集合,是 Google Guava 和 Apache Commons 的替代品。
動(dòng)機(jī):JDK, Guava 和 Apache Commons 是程序化的而不是面向?qū)ο蟮摹K麄冎饕峭ㄟ^(guò)靜態(tài)方法來(lái)工作的。Cactoos 則是通過(guò)面向?qū)ο蟆?/p>
如何使用。庫(kù)沒(méi)有依賴(lài)性,在這里獲得最新版本:
< dependency > < groupId > org.cactoos </ groupId > < artifactId > cactoos </ artifactId > </ dependency >
Java版本要求:1.8+。
StackOverflow標(biāo)簽是cactoos。
輸入輸出
以UTF-8讀取文本文件:
String text = new TextOf( new File(“/ code/a.txt ”) )。asString();
將文本寫(xiě)入文件:
new LengthOf( new TeeInput( “ Hello,world!”, new File(“/ code/a.txt ”) ) )。的intValue();
從classpath讀取二進(jìn)制文件:
byte [] data = new BytesOf( new ResourceOf(“ foo / img.jpg ”) )。asBytes();
評(píng)論
圖片
表情
