这样写输出中文肯定会乱码,因为中文是两个字节表示,只就使用ByteArrayOutputStream,将字节缓存后统一输出,try中代码修改如下:
- try
- {
- fis = new FileInputStream(new File("exercise.txt"));
- ByteArrayOutputStream bos = new ByteArrayOutputStream ();
- byte [] buffer = new byte[5];
- while (fis.read(buffer,0,buffer.length)!=-1)
- {
- bos.write(buffer, 0, 5);
- }
- System.out.println(bos.toString());
- }
复制代码
|