public class ManFileReadWriteExt extends Object
Constructor and Description |
---|
ManFileReadWriteExt() |
Modifier and Type | Method and Description |
---|---|
static void |
appendBytes(File thiz,
byte[] array)
Appends an [array] of bytes to the content of this file.
|
static void |
appendText(File thiz,
String text)
Appends [text] to the content of this file using UTF-8 or the specified [charset].
|
static void |
appendText(File thiz,
String text,
Charset charset) |
static BufferedReader |
bufferedReader(File thiz)
Returns a new [BufferedReader] for reading the content of this file.
|
static BufferedReader |
bufferedReader(File thiz,
Charset charset,
int bufferSize) |
static BufferedWriter |
bufferedWriter(File thiz)
Returns a new [BufferedWriter] for writing the content of this file.
|
static BufferedWriter |
bufferedWriter(File thiz,
Charset charset,
int bufferSize) |
static void |
forEachBlock(File thiz,
BiConsumer<byte[],Integer> action)
Reads file by byte blocks and calls [action] for each block read.
|
static void |
forEachBlock(File thiz,
int blockSize,
BiConsumer<byte[],Integer> action)
Reads file by byte blocks and calls [action] for each block read.
|
static void |
forEachLine(File thiz,
Charset charset,
Consumer<String> action)
Reads this file line by line using the specified [charset] and calls [action] for each line.
|
static FileInputStream |
inputStream(File thiz)
Constructs a new FileInputStream of this file and returns it as a result.
|
static FileOutputStream |
outputStream(File thiz)
Constructs a new FileOutputStream of this file and returns it as a result.
|
static PrintWriter |
printWriter(File thiz)
Returns a new [PrintWriter] for writing the content of this file.
|
static PrintWriter |
printWriter(File thiz,
Charset charset) |
static byte[] |
readBytes(File thiz)
Gets the entire content of this file as a byte array.
|
static InputStreamReader |
reader(File thiz)
Returns a new [FileReader] for reading the content of this file.
|
static InputStreamReader |
reader(File thiz,
Charset charset) |
static List<String> |
readLines(File thiz,
Charset charset)
Reads the file content as a list of lines.
|
static String |
readText(File thiz)
Gets the entire content of this file as a String using UTF-8 or specified [charset].
|
static String |
readText(File thiz,
Charset charset) |
static <T> T |
useLines(File thiz,
Charset charset,
Function<Iterable<String>,T> block)
Calls the [block] callback giving it a sequence of all the lines in this file and closes the reader once
the processing is complete.
|
static void |
writeBytes(File thiz,
byte[] array)
Sets the content of this file as an [array] of bytes.
|
static OutputStreamWriter |
writer(File thiz)
Returns a new [FileWriter] for writing the content of this file.
|
static OutputStreamWriter |
writer(File thiz,
Charset charset) |
static void |
writeText(File thiz,
String text)
Sets the content of this file as [text] encoded using UTF-8 or specified [charset].
|
static void |
writeText(File thiz,
String text,
Charset charset) |
public static InputStreamReader reader(File thiz)
public static InputStreamReader reader(File thiz, Charset charset)
public static BufferedReader bufferedReader(File thiz)
bufferSize
- necessary size of the buffer.public static BufferedReader bufferedReader(File thiz, Charset charset, int bufferSize)
public static OutputStreamWriter writer(File thiz)
public static OutputStreamWriter writer(File thiz, Charset charset)
public static BufferedWriter bufferedWriter(File thiz)
bufferSize
- necessary size of the buffer.public static BufferedWriter bufferedWriter(File thiz, Charset charset, int bufferSize)
public static PrintWriter printWriter(File thiz)
public static PrintWriter printWriter(File thiz, Charset charset)
public static byte[] readBytes(File thiz)
This method is not recommended on huge files. It has an internal limitation of 2 GB byte array size.
public static void writeBytes(File thiz, byte[] array)
array
- byte array to write into this file.public static void appendBytes(File thiz, byte[] array)
array
- byte array to append to this file.public static String readText(File thiz)
This method is not recommended on huge files. It has an internal limitation of 2 GB file size.
charset
- character set to use.public static void writeText(File thiz, String text)
text
- text to write into file.charset
- character set to use.public static void appendText(File thiz, String text)
text
- text to append to file.charset
- character set to use.public static void forEachBlock(File thiz, BiConsumer<byte[],Integer> action)
You can use this function for huge files.
action
- function to process file blocks.public static void forEachBlock(File thiz, int blockSize, BiConsumer<byte[],Integer> action)
You can use this function for huge files.
action
- function to process file blocks.blockSize
- size of a block, replaced by 512 if it's less, 4096 by default.public static void forEachLine(File thiz, Charset charset, Consumer<String> action)
You may use this function on huge files.
charset
- character set to use.action
- function to process file lines.public static FileInputStream inputStream(File thiz)
public static FileOutputStream outputStream(File thiz)
public static List<String> readLines(File thiz, Charset charset)
Do not use this function for huge files.
charset
- character set to use. By default uses UTF-8 charset.public static <T> T useLines(File thiz, Charset charset, Function<Iterable<String>,T> block)
charset
- character set to use. By default uses UTF-8 charset.Copyright © 2024. All rights reserved.