Api函数 file.createnewfile()为何老是报错?

flyshi 2001-06-04 10:40:00
说没有这个API函数?
...全文
163 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
luodi 2001-06-04
  • 打赏
  • 举报
回复
skyyoung讲得足够清楚了。
简化一下,原因有可能两种:
1、大小写写借了,是createNewFile而不是createnewfile,Java可是大小写敏感的;
2、这个方法是JDK1.2后才引入的,如果是用JDK1.2之前的环境编译或运行都不认。
skyyoung 2001-06-04
  • 打赏
  • 举报
回复
createNewFile
public boolean createNewFile()
throws IOException
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. This method, in combination with the deleteOnExit() method, can therefore serve as the basis for a simple but reliable cooperative file-locking protocol.
Returns:
true if the named file does not exist and was successfully created; false if the named file already exists
Throws:
IOException - If an I/O error occurred
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.io.FileDescriptor) method denies write access to the file
Since:
JDK1.2

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧