刚才帮同看问题,同说调用renameTo 文件没有被重命名,看了一下原来问题出在这里
/** * @(#) Test.java Created on 2012-6-4 * * Copyright (c) 2012 Aspire. All Rights Reserved */ package com.and.test; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; /** * The class <code>Test</code> * * @author Administrator * @version 1.0 */ public class Test { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // 源文件 final File src = new File("f:", "a.log"); // 目标文件 final File dest = new File("f:", "b.log"); // 如果文件有人在读取它,则不能被重命名 final InputStream in = new FileInputStream(dest); final boolean con = src.renameTo(dest); if (con) { System.out.println("success"); } else { System.out.println("fail"); } } }
也就是说,源文件在被重命名之前 ,不能有人在读取它,但是java为什么不提供个异常???