* InputStreamReader:字节输出转换为字符输出
* OutStreamWriter:字节输入转换为字符输入
案例
package File类;
import java.io.*;
import java.nio.charset.Charset;
public class 字节字符转换流 {
public static void main(String[] args) throws IOException {
InputStream inputStream = new FileInputStream("1.js");
OutputStream outputStream = new FileOutputStream("1.js");
out(outputStream);
in(inputStream);
}
public static void in(InputStream in) {
try {
Reader reader = new InputStreamReader(in, Charset.defaultCharset());
char[] chars = new char[1024];
int len = -1;
while ((len = reader.read(chars)) != 1) {
System.out.println(new String(chars, 0, len));
}
reader.close();
} catch (Exception e) {
}
}
public static void out(OutputStream out) throws IOException {
Writer writer = new OutputStreamWriter(out,Charset.defaultCharset());
writer.write(",我是新增加");
writer.close();
}
}