日期:2014-05-20  浏览次数:20780 次

没看懂API,来问问
File file = new File("");
  FileReader reader = new FileReader(file);
  char[] buf = new char[(int)file.length()];  
  int len = reader.read(buf);
  String results = new String(buf,0,len);
  System.out.print(results);
定义了一个buf数组长度为file.length,里面应该没有内容
reader.read(buf)是什么意思?
读文件的内容放到buf这个数组中,然后返回数组的长度?

------解决方案--------------------
file.length是文件的字节长度
reader.read(buf);是把文件按字符的方式读入到buf数组中
返回成功读入的字符数,所以和file.length(也就是数组的长度)可能有出入,因为对于多字节字符,字符数和字节数不一样