文件复制
FileWrite和FileReader实现
/**
* 文件复制:原文件 -> 目的文件
* (分段)
*
* @param srcPath 原文件
* @param tarPath 目的文件
* @throws IOException
*/
public static void copyOneFile(String srcPath, String tarPath) throws IOException {
//TODO: 复制: 从src读,写入tar
FileReader fin = new FileReader(srcPath);
FileWriter fout = new FileWriter(tarPath);
char [] buf = new char[30];
int iRead = 0;
while (-1 != (iRead=fin.read(buf))) {
//读取了iRead长度的内容,存放到buf中了
//TODO: 将这部分内容写到tar文件
//String str = new String(buf, 0, iRead);
//fout.write(str);
fout.write(buf, 0, iRead);
}
fout.close();
fin.close();
System.out.println("sss");
}