package com.utils.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileUtilsAdvanced {
// 数组字符流读取 数组字符流写入
public void chararraystream(String str) throws IOException {
CharArrayWriter outchar = new CharArrayWriter();
char b[] = str.toCharArray();
outchar.write(b);
outchar.close();
CharArrayReader inputchar = new CharArrayReader(outchar.toCharArray());
char tmp[] = new char[b.length];
int n = -1;
while ((n = inputchar.read(tmp, 0, 10)) != -1) {
System.out.println(new String(tmp, 0, n));
}
inputchar.close();
}
// 数组字节流写入 数组字节流读取
public void bytearraystream(String str) throws IOException {
ByteArrayOutputStream outbyte = new ByteArrayOutputStream();
byte b[] = str.getBytes();
outbyte.write(b);
outbyte.close();
ByteArrayInputStream inputbyte = new ByteArrayInputStream(
outbyte.toByteArray());
byte tmp[] = new byte[b.length];
int n = -1;
while ((n = inputbyte.read(tmp, 0, 10)) != -1) {
System.out.println(new String(tmp, 0, n));
}
}
}