本帖最后由 qihuan 于 2015-7-14 11:48 编辑
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- private static void copy() {
-
- FileReader fr = null;
- FileWriter fw = null;
-
- try {
- fr = new FileReader("G:\\Demo.txt");
- fw = new FileWriter("G:\\Demo_copy.txt");
-
- char[] buf = new char[1024];
- int len;
- while((len = fr.read(buf)) != -1){
- fw.write(buf,0,len);
- }
- } catch (Exception e) {
- throw new RuntimeException("读写失败");
- } finally {
- if (fr != null) {
- try {
- fr.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (fw != null) {
- try {
- fw.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
- public static void main(String[] args) throws IOException {
- copy();
- }
复制代码
|
|