java单独的线程类里面创建文件出错

我想在单独的线程里面创建文件,用于定时备份文件,但是出错,看代码:

public class WW {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[]a) throws IOException {
        ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(1);
        scheduledExecutorService.scheduleAtFixedRate(new MyBackFileTask(),2,3, TimeUnit.SECONDS);
    }

    static class MyBackFileTask implements Runnable{
        @Override
        public void run() {
            String fileName = sdf.format(new Date())+".txt";
            File file = new File("c:\\",fileName);
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

其中file.createNewFile();这句出错,望大家帮忙分析下

你可能感兴趣的:(java)