public static void main(String[] args) throws Exception {
FileReader fr = new FileReader("c:\\test.txt");// test.txt中内容1234567890
char[] cs = new char[4];
int count = 0;
while ((count = fr.read(cs)) > 0) {
for (int i = 0; i < count; i++) {
System.out.println(cs[i]);
}
}
}
Java实现文件复制
public void fileCopy(String filePath,String savePath){
try{
FileInputStream in = new FileInputStream(filePath);
FileOutputStream out = new FileOutputStream(savePath);
byte[] bt = new byte[1024];
int count;
while ((count = in.read(bt)) > 0) {
out.write(bt, 0, count); //重点
}
in.close();
out.close();
}catch(IOException e){
e.printStackTrace();
}
}