文件系统默认是GBK格式如:- @Test
- public void test3() {
- // InputStream is = System.in;
- InputStreamReader isr = null;
- OutputStreamWriter osw = null;
- try {
- isr = new InputStreamReader(new FileInputStream("d:/hello.java"),
- "utf-8");
- osw = new OutputStreamWriter(new FileOutputStream(
- "d:/hello_write.java"), "utf-8");
- int lenght = 0;
- char[] ch = new char[32];
- while ((lenght = isr.read(ch)) != -1) {
- System.out.print(new String(ch, 0, lenght));
- osw.write(ch, 0, lenght);
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (isr != null) {
- try {
- isr.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (osw != null) {
- try {
- osw.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
复制代码 |