/**
* 对IO的学习-讲一个文件的内容写入到另一个文件中
* @author dlding
* @
*/
public class MyIODemon03 {
/**
*
* @param filein //要读取的文件
* @param fileout //要写入的文件
*/
public static void ReadAdnWrite(String filei,String fileo)
{
File filein=new File(filei);
File fileout=new File(fileo);
InputStreamReader inputstreamreader=null;
OutputStreamWriter outputstreamwriter=null;
try {
inputstreamreader=new InputStreamReader(new FileInputStream(filein));
outputstreamwriter=new OutputStreamWriter(new FileOutputStream(fileout));
int cha=0;
while((cha=inputstreamreader.read())!=-1)
{
outputstreamwriter.write(cha);//写
System.out.println((char)cha);//读
}
outputstreamwriter.flush();//将缓存中的数据写入文件
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{//关闭输入输出流
try {
inputstreamreader.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
outputstreamwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}