转换流
import org.junit.Test;
import java.io.*;
public class TransIOTest {
@Test
public void test() {
File srcFile = new File("F:\\Lean\\Text\\src\\main\\resources\\a.txt");
File destFile = new File("F:\\Lean\\Text\\src\\main\\resources\\b.txt");
FileInputStream fis = null;
FileOutputStream fos = null;
InputStreamReader isr = null;
OutputStreamWriter osw = null;
try {
fis = new FileInputStream(srcFile);
fos = new FileOutputStream(destFile);
isr = new InputStreamReader(fis, "utf-8");
osw = new OutputStreamWriter(fos, "gbk");
char[] chars = new char[1024];
int len;
while ((len = isr.read(chars)) != -1) {
osw.write(chars, 0, len);
}
osw.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (isr != null) {
isr.close();
}
if (osw != null) {
osw.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}