InputStreamReader ()
OutputStreamWriter ()
public static void main(String[] args) throws IOException {
method_01();
}
public static void method_01() throws IOException {
// InputStreamReader dome 转换流
// E:\folder_io_dome\domeDir03\a2.txt
FileInputStream fileInputStream = new FileInputStream("E:\\folder_io_dome\\domeDir03\\a2.txt");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "GBK");
// will data save memory
String data = new String();
int len = 0;
char[] char_arr = new char[1024];
while ((len = inputStreamReader.read(char_arr)) != -1) {
System.out.println(new String(char_arr, 0, len));
// save data
data = new String(char_arr, 0, len);
}
String[] split = data.split("\n");
System.out.println(split.length);
// close stream 关闭流
fileInputStream.close();
inputStreamReader.close();
// OutputStreamWrite dome 转换流 将内存中的字符串写入到硬盘中
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream("E:\\folder_io_dome\\domeDir03\\a3.txt"), "UTF-8");
for (int i = 0; i < split.length; i++) {
for (int i1 = 0; i1 < split[i].toCharArray().length; i1++) {
outputStreamWriter.write(split[i].toCharArray()[i1]);
}
}
outputStreamWriter.flush();
}
}