标签:
package a.ab; import java.io.*; public class FileWrite { public static void main(String[] args) { FileReader fr=null; try{ File f=new File("D:\\DD\\d.txt"); int num=0; fr=new FileReader(f); char [] buf =null; for(int i=0;i<f.length();i++){ buf =new char[3]; num=fr.read(buf); if(num==-1){ System.out.println("文件已经读取完毕!"); break; } System.out.println("读取了"+num+"个字符,分别是:"+ new String(buf,0,num)); } fr.close(); }catch(Exception ex){ ex.printStackTrace(); } } }
package a.ab; import java.io.*; public class FileWrite { public static void main(String[] args) { FileReader fr=null; try{ File f=new File("D:\\DD\\d.txt"); int num=0; fr=new FileReader(f); char [] cbuf =new char[3]; while((num=fr.read(cbuf))!=-1){ System.out.println("读取了"+num+"个字符,分别是:"+ new String(cbuf,0,num)); } System.out.println("文件已经读取完毕!"); fr.close(); }catch(Exception ex){ ex.printStackTrace(); } } }
public int read(char[] cbuf) throws IOException
cbuf
- 目标缓冲区IOException
- 如果发生 I/O 错误标签:
原文地址:http://www.cnblogs.com/LYL-1314/p/5720458.html