# File类 下面创建文件的代码错误的是: ## 答案 ```java File file = new File("C:\\newfile.txt"); file.mkdirs(); ``` ## 选项 ### A ```java File file = new File("C:\\newfile.txt"); file.createNewFile(); ``` ### B ```java File file = new File("/tmp/newfile.txt"); if(!file.exists()) { file.createNewFile(); } ``` ### C ```java File file = new File("/tmp/newfile.txt"); try{ file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } ``` ### D 以上都是