add IO.toStringLines
This commit is contained in:
@ -11,6 +11,7 @@ import com.imyeyu.utils.Text;
|
||||
import javax.naming.NoPermissionException;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -352,6 +353,19 @@ public class IO implements OS.FileSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] toStringLines(File file) throws IOException {
|
||||
return toString(file).split("\r\n|[\r\n]");
|
||||
}
|
||||
|
||||
public static void toStringLines(File file, CallbackArg<String> lineCallback) throws IOException {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
lineCallback.handler(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件为字符串(UTF-8)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user