《java----IO流---文件复制》
程序员文章站
2024-03-04 16:50:23
...
import java.io.FileReader;
import java.io.FileWriter;
class IOTest
{
public static void main(String[] args)
{
FileReader fr = null;
FileWriter fw = null;
try
{
fr = new FileReader("EditPlus.txt");
fw = new FileWriter("MYIOEditPlus.txt");
char [] cbuf = new char [1024];
int len = 0;
while((len = fr.read(cbuf)) != -1)
{
fw.write(cbuf, 0, len);
}
}
catch (Exception e)
{
throw new RuntimeException("文件读取失败!");
}
finally
{
if(fr != null)
try
{
fr.close();
}
catch (Exception e)
{
}
if(fw != null)
try
{
fw.close();
}
catch (Exception e)
{
}
}
}
}
下一篇: File跟Io流的学习