- /**
- * 从C盘读一个字符,就往D盘写一个字符
- */
- public static void copyFileTest2() {
- FileWriter fw = null;
- FileReader fr = null;
- try {
- fw = new FileWriter(path + "RuntimeDemo_copy.txt");// 写入
- fr = new FileReader("C:/" + "demo4.txt"); // 读
- int ch = 0;
- while ((ch = fr.read()) != -1) {
- fw.write(ch);
- }
- System.out.println("写入成功!");
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (fr != null) {
- try {
- fr.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (fr != null) {
- try {
- fr.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
复制代码 请问,程序正常结束,文件也创建,但是新建文件没有字符内容,这是怎么回事?求解答 |