黑马程序员技术交流社区
标题:
黑马入学考试题 5
[打印本页]
作者:
nagi
时间:
2014-9-18 12:38
标题:
黑马入学考试题 5
定义一个文件输入流,调用read(byte[] b)方法将exercise.txt文件中的所有内容打印出来(byte数组的大小限制为5)。
大家都是什么做的,,,有木有考虑中文乱码的问题啊!!!:#
作者:
默默丶
时间:
2014-9-18 17:19
import java.io.*;
public class Demo
{
public static void main(String[] args)throws IOException
{
FileInputStream fis = new FileInputStream("exercise.txt");
PrintStream fos =System.out;
byte[] buf =new byte[5];
int len = 0;
while((len=fis.read(buf))!=-1)
{
fos.write(buf,0,len);
fos.flush();
}
fos.close();
fis.close();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2