public void readByReader(String path){
Reader reader=null;
Writer writer=null;
int temp=0;
try {
reader=new FileReader(path);
//初始化字符输出流
writer=new FileWriter("e:/JAVA/新建文件夹/复制七里香.txt");
while ((temp=reader.read())!=-1){
writer.write(temp);
System.out.print((char) temp);
}
reader.close();
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public class MainView {
public static void main(String[] args) {
FileUtils fileUtils = new FileUtils();
// fileUtils.readByInputStream("E:/JAVA/新建文件夹/rightherewaiting.txt");
//// fileUtils.writeByOutputStream("what are u doing");
//// fileUtils.writeByOutputStream("roses");
// fileUtils.readByReader("E:/JAVA/新建文件夹/七里香.txt");
fileUtils.readByBuffer("E:/JAVA/新建文件夹/七里香.txt");
}
}
原文:https://www.cnblogs.com/aojie/p/12380556.html